:root {
  --ink: #25211e;
  --muted: #817a74;
  --line: #e6dfd7;
  --paper: #fffefa;
  --canvas: #f3f0e9;
  --accent: #c95e36;
  --accent-dark: #9e3f23;
  --accent-soft: #faeee8;
  --ok: #367458;
  --danger: #b23a38;
  font-family: "Avenir Next", "Hiragino Sans", "Yu Gothic", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
body { min-width: 0; min-height: 100dvh; margin: 0; overflow-x: hidden; background: radial-gradient(circle at 85% 0%, #fff8eb 0, transparent 32rem), var(--canvas); }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.shell { width: min(1120px, calc(100% - 40px)); margin: 0 auto; min-height: 100dvh; padding-bottom: calc(56px + env(safe-area-inset-bottom)); }
.brandbar { height: 76px; display: flex; align-items: center; justify-content: space-between; }
.brand { display: inline-flex; min-width: 0; align-items: center; gap: 12px; color: var(--ink); text-decoration: none; font-weight: 800; letter-spacing: .08em; }
.brand > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; color: white; background: var(--ink); font-family: Georgia, serif; }
.brand-logo { display: block; width: 38px; height: 38px; border-radius: 10px; object-fit: contain; }
.brand-actions { display: flex; align-items: center; gap: 10px; }
.language-picker { display: block; margin: 0; }
.language-picker select { height: 40px; padding: 0 32px 0 12px; border: 1px solid #d9d0c7; border-radius: 10px; color: var(--ink); background: var(--paper); }

.login-layout { min-height: calc(100dvh - 132px); display: grid; grid-template-columns: 1.2fr .8fr; align-items: center; gap: 72px; }
.login-copy h1 { max-width: 720px; margin: 12px 0 18px; font-family: Georgia, "Yu Mincho", serif; font-size: clamp(42px, 6vw, 78px); line-height: 1.03; font-weight: 500; }
.login-copy > p:last-child { color: var(--muted); font-size: 18px; }
.eyebrow { margin: 0; color: var(--accent-dark); font-size: 12px; font-weight: 800; letter-spacing: .16em; }
.panel, .tab-panel { border: 1px solid var(--line); border-radius: 22px; background: rgba(255, 254, 250, .92); box-shadow: 0 18px 50px rgba(69, 55, 43, .07); }
.login-panel { padding: 32px; }
.login-panel h2 { margin: 0 0 24px; font-size: 26px; }
label { display: grid; gap: 8px; margin-bottom: 18px; font-size: 13px; font-weight: 700; }
input { width: 100%; height: 48px; padding: 0 14px; border: 1px solid #d9d0c7; border-radius: 10px; color: var(--ink); background: white; outline: none; }
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.button { min-height: 40px; padding: 0 16px; border: 1px solid #d9d0c7; border-radius: 10px; color: var(--ink); background: var(--paper); font-weight: 700; }
.button:hover { border-color: #bcaea1; background: #fff; }
.button-primary { border-color: var(--accent); color: white; background: var(--accent); }
.button-primary:hover { border-color: var(--accent-dark); background: var(--accent-dark); }
.button-danger { color: var(--danger); background: var(--paper); }
.button-danger:hover { border-color: #dba3a0; background: #fff7f6; }
.button-quiet { background: transparent; }
.login-panel .button-primary { width: 100%; margin-top: 4px; }
.form-error, .notice-error { color: var(--danger); }
.form-error { margin: -4px 0 16px; font-size: 13px; }
.form-success { margin: -4px 0 16px; color: var(--ok); font-size: 13px; }
.login-links { display: flex; justify-content: space-between; gap: 16px; margin-top: 18px; }
.text-button { padding: 0; border: 0; color: var(--accent-dark); background: transparent; font-size: 13px; font-weight: 700; }
.text-button:hover { text-decoration: underline; }
.heading-actions { display: flex; align-items: center; gap: 10px; }
.code-input-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; }
.code-input-row .button { min-width: 112px; }
.human-challenge { display: grid; grid-template-columns: minmax(0, 220px) auto; gap: 10px; align-items: center; margin-bottom: 18px; }
.human-challenge img { display: block; width: 220px; height: 72px; border: 1px solid var(--line); border-radius: 10px; background: #f6f1ea; }
.danger-section { background: #fff9f8; }

.account-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; padding: 46px 0 28px; }
.account-heading h1 { margin: 8px 0 0; font-family: Georgia, "Yu Mincho", serif; font-size: 48px; font-weight: 500; }
.identity-chip { min-width: 230px; padding: 14px 18px; border-left: 3px solid var(--accent); background: rgba(255, 254, 250, .68); }
.identity-chip span { display: block; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .1em; }
.identity-chip strong { display: block; margin-top: 4px; font-size: 20px; }
.tabs { display: flex; gap: 4px; margin-bottom: 16px; padding: 5px; width: fit-content; border: 1px solid var(--line); border-radius: 12px; background: rgba(255, 254, 250, .72); }
.tab { min-height: 38px; padding: 0 18px; border: 0; border-radius: 8px; color: var(--muted); background: transparent; font-weight: 700; }
.tab.active { color: white; background: var(--ink); }
.notice { margin-bottom: 16px; padding: 13px 16px; border: 1px solid #e8b4af; border-radius: 10px; background: #fff4f2; }
.tab-panel > .notice { margin: 16px 22px 0; }
.tab-panel { overflow: hidden; }
.section-heading { min-height: 72px; padding: 18px 22px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); }
.section-heading h2 { margin: 0; font-size: 18px; }
.section-heading p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.section-heading-subsection { border-top: 1px solid var(--line); }
.data-table { margin: 0; }
.data-table > div { display: grid; grid-template-columns: 220px 1fr; min-height: 56px; border-bottom: 1px solid var(--line); }
.data-table > div:last-child { border-bottom: 0; }
.data-table dt, .data-table dd { margin: 0; padding: 16px 22px; }
.data-table dt { color: var(--muted); background: #faf8f4; }
.data-table dd { min-width: 0; overflow-wrap: anywhere; font-weight: 600; }
.game-list, .identity-list { display: grid; }
.game-row { display: grid; grid-template-columns: minmax(200px, 1.4fr) minmax(140px, 1fr); gap: 24px; align-items: center; min-height: 72px; padding: 14px 22px; border-bottom: 1px solid var(--line); }
.identity-row { display: grid; grid-template-columns: minmax(170px, 1fr) minmax(180px, 1.4fr) minmax(100px, .6fr) auto; gap: 20px; align-items: center; min-height: 72px; padding: 14px 22px; border-bottom: 1px solid var(--line); }
.game-row:last-child, .identity-row:last-child { border-bottom: 0; }
.game-row > *, .identity-row > *, .session-row > * { min-width: 0; }
.game-row strong, .identity-row strong { display: block; overflow-wrap: anywhere; }
.game-row span, .identity-row span { color: var(--muted); font-size: 13px; }
.identity-status { width: fit-content; padding: 5px 9px; border-radius: 999px; font-weight: 700; white-space: nowrap; }
.identity-status.is-bound { color: var(--ok); background: #eef7f2; }
.identity-status.is-unbound { color: var(--muted); background: #f4f1ed; }
.identity-row .button { min-width: 76px; }
.identity-row .button:disabled { cursor: not-allowed; opacity: .45; }
.empty { padding: 46px 22px; color: var(--muted); text-align: center; }
.security-summary { border-bottom: 1px solid var(--line); }
.subsection-heading { min-height: 54px; display: flex; align-items: center; padding: 12px 22px; border-bottom: 1px solid var(--line); }
.subsection-heading h3 { margin: 0; font-size: 15px; }
.session-list { display: grid; }
.session-row { display: grid; grid-template-columns: minmax(180px, 1.4fr) repeat(2, minmax(150px, 1fr)) auto; gap: 24px; align-items: center; min-height: 76px; padding: 14px 22px; border-bottom: 1px solid var(--line); }
.session-row:last-child { border-bottom: 0; }
.session-row strong, .session-row span { display: block; }
.session-row span { color: var(--muted); font-size: 12px; }
.session-current { padding: 6px 10px; border-radius: 999px; color: var(--ok) !important; background: #eef7f2; font-weight: 700; white-space: nowrap; }
.account-footer { display: flex; justify-content: center; gap: 22px; padding: 28px 0 0; }
.account-footer a { color: var(--muted); font-size: 13px; text-decoration: none; }
.account-footer a:hover { color: var(--accent-dark); }

dialog { width: min(520px, calc(100% - 32px)); max-height: calc(100dvh - 32px); padding: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 18px; color: var(--ink); background: var(--paper); box-shadow: 0 24px 80px rgba(31, 25, 20, .2); }
dialog::backdrop { background: rgba(37, 33, 30, .44); backdrop-filter: blur(3px); }
dialog > form { display: grid; max-height: calc(100dvh - 32px); grid-template-rows: auto minmax(0, 1fr) auto; }
.dialog-heading, .dialog-actions { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; }
.dialog-heading { border-bottom: 1px solid var(--line); }
.dialog-heading h2 { margin: 0; font-size: 20px; }
.close-button { width: 36px; height: 36px; border: 0; border-radius: 8px; color: var(--muted); background: transparent; font-size: 24px; }
.dialog-body { overflow-y: auto; padding: 22px; overscroll-behavior: contain; }
.dialog-body p { color: var(--muted); font-size: 13px; line-height: 1.6; }
.handoff-preview { display: grid; gap: 10px; margin: 16px 0 0; }
.handoff-preview div { display: grid; grid-template-columns: 90px minmax(0, 1fr); gap: 12px; }
.handoff-preview dt { color: var(--muted); font-size: 13px; }
.handoff-preview dd { margin: 0; overflow: hidden; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.dialog-actions { justify-content: flex-end; gap: 10px; border-top: 1px solid var(--line); }

@media (max-width: 760px) {
  .shell {
    width: 100%;
    padding-right: max(16px, env(safe-area-inset-right));
    padding-bottom: calc(32px + env(safe-area-inset-bottom));
    padding-left: max(16px, env(safe-area-inset-left));
  }
  .brandbar { height: auto; min-height: 64px; gap: 12px; padding-top: env(safe-area-inset-top); }
  .brand { gap: 9px; font-size: 13px; }
  .brand-logo, .brand-mark { width: 34px; height: 34px; flex: 0 0 auto; }
  .brand-actions { flex: 0 0 auto; gap: 6px; }
  .language-picker select { min-width: 86px; height: 44px; }
  .brand-actions .button { min-height: 44px; padding-inline: 12px; }
  .login-layout { min-height: 0; grid-template-columns: 1fr; align-content: start; gap: 16px; padding: 16px 0 32px; }
  .login-copy h1 { margin: 6px 0 0; font-size: clamp(26px, 7vw, 30px); line-height: 1.08; }
  .login-copy > p:last-child { display: none; }
  .login-panel { padding: 20px; border-radius: 16px; }
  .login-panel h2 { margin-bottom: 18px; font-size: 22px; }
  .login-panel label { margin-bottom: 16px; }
  input { min-height: 48px; font-size: 16px; }
  .login-panel .button-primary { min-height: 48px; }
  .account-heading { align-items: stretch; flex-direction: column; gap: 14px; padding: 22px 0 18px; }
  .account-heading h1 { margin-top: 5px; font-size: 32px; }
  .identity-chip { min-width: 0; padding: 11px 14px; }
  .identity-chip strong { overflow-wrap: anywhere; font-size: 18px; }
  .tabs { width: 100%; margin-bottom: 12px; overflow-x: auto; overscroll-behavior-inline: contain; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { min-width: 104px; min-height: 44px; flex: 1 0 auto; padding-inline: 14px; }
  .tab-panel { border-radius: 16px; }
  .section-heading { min-height: 0; align-items: stretch; flex-direction: column; gap: 12px; padding: 15px 16px; }
  .section-heading h2 { font-size: 17px; }
  .section-heading p { line-height: 1.5; }
  .section-heading .button { width: 100%; min-height: 44px; }
  .heading-actions { width: 100%; align-items: stretch; flex-direction: column; gap: 8px; }
  .login-links { margin-top: 16px; }
  .code-input-row { grid-template-columns: 1fr; }
  .code-input-row .button { min-height: 44px; }
  .human-challenge { grid-template-columns: 1fr; }
  .human-challenge img { width: 100%; max-width: 220px; }
  .tab-panel > .notice { margin: 12px 16px 0; }
  .data-table > div { min-height: 52px; grid-template-columns: minmax(96px, .42fr) minmax(0, 1fr); }
  .data-table dt, .data-table dd { padding: 13px 16px; }
  .data-table dt { background: #faf8f4; }
  .data-table dd { text-align: left; }
  .subsection-heading { min-height: 48px; padding-inline: 16px; }
  .game-row { min-height: 64px; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; padding: 12px 16px; }
  .game-row > span { max-width: 116px; text-align: right; }
  .identity-row { min-height: 76px; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; padding: 12px 16px; }
  .identity-row > strong { grid-column: 1; grid-row: 1; }
  .identity-row .identity-account { overflow: hidden; grid-column: 1; grid-row: 2; text-overflow: ellipsis; white-space: nowrap; }
  .identity-row .identity-status { grid-column: 2; grid-row: 1; }
  .identity-row .button { min-width: 88px; min-height: 44px; grid-column: 2; grid-row: 2; }
  .session-row { min-height: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; padding: 14px 16px; }
  .session-row > div:first-child { grid-column: 1 / -1; }
  .session-row .button, .session-current { width: 100%; min-height: 44px; grid-column: 1 / -1; margin-top: 2px; }
  .session-current { display: grid !important; place-items: center; }
  .empty { padding: 36px 16px; }
  .account-footer { flex-wrap: wrap; gap: 12px 20px; padding-top: 22px; }
  dialog {
    width: calc(100% - 16px);
    max-height: calc(100dvh - max(16px, env(safe-area-inset-top)) - max(16px, env(safe-area-inset-bottom)));
    border-radius: 16px;
  }
  dialog > form { max-height: calc(100dvh - max(16px, env(safe-area-inset-top)) - max(16px, env(safe-area-inset-bottom))); }
  .dialog-heading { min-height: 60px; padding: 12px 16px; }
  .dialog-heading h2 { font-size: 18px; }
  .close-button { width: 44px; height: 44px; flex: 0 0 auto; }
  .dialog-body { padding: 18px 16px; }
  .dialog-actions { gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: var(--paper); }
  .dialog-actions .button { min-height: 44px; flex: 1 1 0; }
}
