/* random9 — チャコール背景・白文字・赤ピンクのアクセントだけで構成するダークテーマ */
:root {
  --bg: #0c0c0e;
  --card: #16161a;
  --field: #0f0f12;
  --raise: #25252b;
  --ink: #f5f5f7;
  --ink-2: #cfcfd5;
  --muted: #9b9ba5;
  --line: #2a2a31;
  --control-line: #4a4a54;
  --accent: #e5174f;
  --accent-press: #c9123f;
  --accent-hi: #ff4574;
  --accent-tint: rgba(255, 69, 116, .32);
  --danger: #ff6b8a;

  --radius: 12px;
  --radius-lg: 18px;
  --pill: 999px;
  --ease: cubic-bezier(.2, .6, .2, 1);
  --gap: clamp(10px, 1.8vh, 18px);
  --sans: -apple-system, BlinkMacSystemFont, system-ui, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Segoe UI", Roboto, sans-serif;
  --display: var(--sans);
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 var(--sans);
  letter-spacing: -.003em;
  font-feature-settings: "palt" 0;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
html, body { height: 100%; margin: 0; overflow: hidden; }
[hidden] { display: none !important; }
::selection { background: var(--accent-tint); }

.app {
  height: 100vh; height: 100dvh;
  max-width: 520px; margin: 0 auto;
  display: flex; flex-direction: column; gap: var(--gap);
  padding: max(env(safe-area-inset-top), 8px) max(env(safe-area-inset-right), 20px) max(env(safe-area-inset-bottom), 10px) max(env(safe-area-inset-left), 20px);
}

/* ---------- ヘッダー ---------- */
.top { flex: none; display: flex; align-items: center; gap: 8px; min-height: 44px; }
.brand { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
.brand img { width: 28px; height: 28px; border-radius: 6px; display: block; }
.brand-name { margin: 0; font-family: var(--display); font-size: 1.0625rem; font-weight: 600; letter-spacing: -.02em; }
.actions { display: flex; align-items: center; gap: 0; margin-right: -10px; }

.ghost {
  font: inherit; font-size: .8125rem; font-weight: 500; color: var(--ink-2);
  background: none; border: 0; border-radius: var(--pill); text-decoration: none; cursor: pointer;
  min-height: 40px; padding: 0 14px; display: inline-flex; align-items: center; white-space: nowrap;
  transition: background-color .12s var(--ease), color .12s var(--ease);
}
.ghost:hover { background: var(--raise); color: var(--ink); }
.ghost:active { background: #303038; }

/* ---------- ステージ ---------- */
.stage { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: var(--gap); justify-content: safe center; }
.panels { flex: 0 1 auto; min-height: 0; display: flex; flex-direction: column; gap: var(--gap); }
.badges { flex: none; list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 2px 20px; color: var(--ink-2); font-size: .75rem; font-weight: 500; }
.badges li { display: inline-flex; align-items: center; gap: 7px; padding: 4px 0; }

.badges svg { color: var(--accent-hi); flex: none; }

/* ---------- カード ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: clamp(12px, 2.2vh, 20px); }
.settings { flex: none; }
.result { flex: 0 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 6px; }
.result-title { margin: 0; text-align: center; font-size: .8125rem; font-weight: 600; color: var(--ink-2); letter-spacing: 0; }
.result-body { flex: 1 1 auto; min-height: 64px; overflow: auto; display: flex; scrollbar-width: thin; scrollbar-color: #4a4a54 transparent; }
.out {
  margin: auto 0; width: 100%; text-align: center;
  font: 600 clamp(36px, 9.6vw, 52px)/1.15 var(--display);
  font-variant-numeric: tabular-nums; letter-spacing: -.035em;
  color: var(--ink); overflow-wrap: anywhere; word-break: break-all; text-wrap: balance; user-select: all;
}
.out.mono { font-family: var(--mono); font-weight: 600; font-variant-numeric: tabular-nums slashed-zero; font-size: clamp(22px, 6.4vw, 30px); letter-spacing: -.01em; }
.out.multi { margin: 0; text-align: left; font-size: clamp(16px, 4.6vw, 20px); font-weight: 500; line-height: 1.75; letter-spacing: 0; }
.placeholder { margin: auto 0; width: 100%; text-align: center; color: var(--muted); font: 400 .9375rem/1.6 var(--sans); letter-spacing: 0; user-select: none; }
.result[data-state="empty"] .out { display: none; }
.result:not([data-state="empty"]) .placeholder { display: none; }
.panes { display: grid; }
.panes > [role="tabpanel"] { grid-area: 1 / 1; }
.panes > [hidden] { display: block !important; visibility: hidden; }

.gauge { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; width: min(220px, 70%); margin: 2px auto 0; visibility: hidden; }
.gauge.on { visibility: visible; }
.gauge span { height: 6px; border-radius: 3px; background: #2c2c33; }
.gauge span.fill { background: var(--accent-hi); }
.detail { margin: 0; min-height: 1.5em; text-align: center; color: var(--muted); font-size: .75rem; line-height: 1.5; }
.result-actions { flex: none; display: grid; grid-template-columns: 1fr; margin-top: 6px; }

/* ---------- フォーム ---------- */
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; padding: 3px; margin-bottom: clamp(10px, 2vh, 16px); background: var(--field); border: 1px solid var(--line); border-radius: var(--pill); }
.tabs button {
  min-height: 38px; border: 0; border-radius: var(--pill); background: transparent; color: var(--muted);
  font: inherit; font-size: .875rem; font-weight: 600; cursor: pointer;
}
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected="true"] { background: var(--raise); color: var(--ink); }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; align-items: end; }
.row2.range { grid-template-columns: 1fr auto 1fr; gap: 10px; }
.tilde { height: 44px; display: flex; align-items: center; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; margin-bottom: 12px; }
.row2 .field { margin-bottom: 0; }
label { font-size: .78rem; font-weight: 500; color: var(--muted); }
output { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; }

input[type="text"], input[type="number"] {
  width: 100%; height: 44px; padding: 0 14px; border-radius: var(--radius);
  border: 1px solid var(--control-line); background: var(--field); color: var(--ink);
  font: inherit; font-size: 1rem; letter-spacing: -.005em; font-variant-numeric: tabular-nums;
  transition: border-color .12s var(--ease), box-shadow .12s var(--ease);
}
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type="text"]:hover, input[type="number"]:hover { border-color: #6a6a76; }
input[type="text"]:focus, input[type="number"]:focus { outline: none; border-color: var(--accent-hi); box-shadow: 0 0 0 3px var(--accent-tint); }

.checks { display: flex; flex-wrap: wrap; gap: 0 22px; margin-bottom: 2px; }
.check { position: relative; display: inline-flex; align-items: center; min-height: 44px; font-size: .9375rem; font-weight: 450; color: var(--ink); cursor: pointer; }
.check input { position: absolute; left: 0; top: 50%; width: 20px; height: 20px; margin: -10px 0 0; opacity: 0; cursor: pointer; }
.check span { position: relative; padding-left: 30px; line-height: 1.35; }
.check span::before {
  content: ""; position: absolute; left: 0; top: 50%; width: 20px; height: 20px; margin-top: -10px;
  border: 1.5px solid var(--control-line); border-radius: 6px; background: var(--field);
  transition: background-color .12s var(--ease), border-color .12s var(--ease), box-shadow .12s var(--ease);
}
.check span::after {
  content: ""; position: absolute; left: 7px; top: 50%; width: 5px; height: 9px; margin-top: -7px;
  border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg) scale(.6); opacity: 0;
  transition: opacity .12s var(--ease), transform .12s var(--ease);
}
.check:hover span::before { border-color: #6a6a76; }
.check input:checked + span::before { background: var(--accent); border-color: var(--accent); }
.check input:checked + span::after { opacity: 1; transform: rotate(45deg) scale(1); }
.check input:focus-visible + span::before { box-shadow: 0 0 0 3px var(--accent-tint); border-color: var(--accent-hi); }

input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 28px; margin: 0; background: transparent; cursor: pointer; --p: 50; }
input[type="range"]:focus { outline: none; }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(to right, var(--accent) calc(var(--p) * 1%), #2c2c33 calc(var(--p) * 1%)); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; margin-top: -9px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 1px 4px rgba(0, 0, 0, .6); transition: box-shadow .12s var(--ease); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: #2c2c33; }
input[type="range"]::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--accent); }
input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 1px 4px rgba(0, 0, 0, .6); }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 5px var(--accent-tint); }
input[type="range"]:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 5px var(--accent-tint); }

.note { margin: 0 0 4px; color: var(--muted); font-size: .78rem; }
.error { margin: 0 0 6px; min-height: 1.5em; color: var(--danger); font-size: .8125rem; line-height: 1.5; }

button { font: inherit; }
.primary, .secondary { cursor: pointer; border-radius: var(--pill); font-weight: 600; letter-spacing: 0; }
.primary {
  width: 100%; height: 48px; border: 0; background: var(--accent); color: #fff; font-size: .9375rem;
  transition: background-color .12s var(--ease), transform .08s var(--ease);
}
.primary:hover { background: #f21f58; }
.primary:active { background: var(--accent-press); transform: scale(.985); }
.primary:disabled { background: #2e2e35; color: #777; cursor: default; }
.secondary {
  min-height: 44px; padding: 0 18px; border: 1px solid var(--control-line); background: #101013; color: var(--ink); font-size: .8125rem;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap;
  transition: background-color .12s var(--ease), border-color .12s var(--ease), transform .08s var(--ease);
}
.secondary svg { flex: none; color: var(--ink-2); }
.secondary:hover:not(:disabled) { background: #1d1d22; border-color: #6a6a76; }
.secondary:active:not(:disabled) { background: #303038; transform: scale(.98); }
.secondary:disabled { color: #6b6b74; border-color: var(--line); cursor: default; }
.secondary:disabled svg { color: #6b6b74; }

a { color: var(--accent-hi); }
:focus-visible { outline: 2px solid var(--accent-hi); outline-offset: 2px; }
input[type="text"]:focus-visible, input[type="number"]:focus-visible, input[type="range"]:focus-visible, .check input:focus-visible { outline: none; }

.toast {
  position: fixed; left: 50%; bottom: max(env(safe-area-inset-bottom), 20px); transform: translate(-50%, 8px);
  background: var(--ink); color: #0c0c0e; font-size: .8125rem; font-weight: 600; padding: 9px 16px; border-radius: var(--radius);
  box-shadow: 0 8px 24px -8px rgba(0, 0, 0, .8); opacity: 0; pointer-events: none;
  transition: opacity .16s var(--ease), transform .16s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 使い方・仕組みダイアログ ---------- */
dialog {
  width: min(540px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0;
  background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: 0 24px 60px -16px rgba(0, 0, 0, .9);
}
dialog::backdrop { background: rgba(0, 0, 0, .7); }
dialog[open] { display: flex; flex-direction: column; animation: pop .16s var(--ease); }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.99); } to { opacity: 1; transform: none; } }
.dlg-head { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px 14px 24px; }
.dlg-head h2 { margin: 0; font-family: var(--display); font-size: 1.125rem; font-weight: 600; letter-spacing: -.02em; }
.icon-btn { flex: none; width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; padding: 0; border: 0; border-radius: var(--pill); background: var(--raise); color: var(--ink-2); cursor: pointer; transition: background-color .12s var(--ease), color .12s var(--ease); }
.icon-btn:hover { background: #303038; color: var(--ink); }
.icon-btn:active { background: #3a3a43; }
.dlg-body { overflow: auto; padding: 0 24px 24px; scrollbar-width: thin; scrollbar-color: #4a4a54 transparent; }
.dlg-body h3 { margin: 22px 0 4px; font-size: .9375rem; font-weight: 600; color: var(--ink); letter-spacing: 0; }
.dlg-body strong { color: var(--ink); font-weight: 600; }
.dlg-body h3:first-child { margin-top: 6px; }
.dlg-body p { margin: 0; white-space: pre-line; font-size: .875rem; line-height: 1.85; color: var(--ink-2); }
code { font: .88em var(--mono); background: var(--field); color: var(--accent-hi); padding: 1px 6px; border-radius: 5px; }
.noscript { position: fixed; inset: 0; margin: 0; padding: 24px; background: var(--bg); color: var(--ink); z-index: 9; }

/* ---------- 狭い画面(スマホ縦): 3項目を縦に並べる ---------- */
@media (max-width: 599px) and (orientation: portrait) {
  .badges { flex-direction: column; flex-wrap: nowrap; gap: 0; }
}

/* ---------- 高さが足りない縦長画面: 部品を詰める ---------- */
@media (max-height: 680px) {
  .card { padding: 12px; }
  .tabs { margin-bottom: 10px; }
  .tabs button { min-height: 34px; }
  input[type="text"], input[type="number"] { height: 40px; }
  .tilde { height: 40px; }
  .check { min-height: 40px; }
  .field, .row2 { margin-bottom: 8px; }
  .primary { height: 44px; }
  .secondary { min-height: 38px; }
  .result-body { min-height: 44px; }
  .out { font-size: 32px; }
}

/* ---------- 横長の画面: 操作カードを中央に、少し大きく ---------- */
@media (orientation: landscape) and (min-width: 820px) and (min-height: 520px) {
  .app { max-width: none; padding-left: max(env(safe-area-inset-left), clamp(24px, 4vw, 72px)); padding-right: max(env(safe-area-inset-right), clamp(24px, 4vw, 72px)); }
  .stage { width: min(100%, clamp(480px, 40vw, 680px)); margin-inline: auto; }
  .result-body { min-height: calc(clamp(40px, min(5vw, 9vh), 80px) * 1.2); }
  .out { font-size: clamp(40px, min(5vw, 9vh), 80px); }
  .out.mono { font-size: clamp(22px, min(2.6vw, 5vh), 40px); }
  .out.multi { font-size: clamp(16px, min(1.6vw, 3vh), 22px); }
}

/* ---------- 低い横向き(スマートフォン): 設定と結果を左右に並べる ---------- */
@media (orientation: landscape) and (max-height: 519px) {
  .app { max-width: none; gap: 6px; padding-left: max(env(safe-area-inset-left), 20px); padding-right: max(env(safe-area-inset-right), 20px); }
  .top { min-height: 36px; }
  .ghost { min-height: 34px; }
  .stage { justify-content: flex-start; }
  .panels { flex: 1; flex-direction: row; align-items: stretch; gap: 14px; }
  .settings { flex: 1; min-width: 0; overflow: auto; scrollbar-width: thin; }
  .result { flex: 1; min-width: 0; min-height: 0; }
  .badges { order: 2; font-size: .6875rem; }
  .badges li { padding-block: 0; }
  .out { font-size: clamp(28px, 6vw, 40px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
