:root {
  --mono: 'Space Mono', ui-monospace, Menlo, monospace;
  --sans: Inter, system-ui, -apple-system, sans-serif;
  color-scheme: dark;
  --bg: #17172b; --panel: #22223b;
  --fg: #f2e9e4; --fg-soft: #c9ada7; --muted: #9e909c;
  --line: #3b3d59; --line-soft: #2b2c46;
  --accent: #c9ada7; --danger: #f0a39b;
}
:root[data-theme='light'] {
  color-scheme: light;
  --bg: #f2e9e4; --panel: #fbf7f5;
  --fg: #22223b; --fg-soft: #4a4e69; --muted: #6c6076;
  --line: #d8c6bf; --line-soft: #e8dcd6;
  --accent: #4a4e69; --danger: #9b3029;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--fg); overflow-wrap: anywhere; font: 400 15px/1.6 var(--sans); }
h1, h2, h3, p { margin: 0; }
h1, h2, h3, legend, .brand { font-family: var(--mono); font-weight: 700; letter-spacing: -.03em; }
.lbl, nav button, .row > span, .group h2, .meta, #exit, .history small {
  font: 400 11px/1.4 var(--mono); letter-spacing: .14em; text-transform: uppercase;
}
.wrap { width: min(64rem, calc(100% - 2 * clamp(16px, 4vw, 48px))); margin-inline: auto; }

header .bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 4.5rem; }
.brand { display: flex; align-items: baseline; gap: .6rem; font-size: 15px; }
.brand .lbl { color: var(--muted); font-weight: 400; }
.bar .actions { display: flex; align-items: center; gap: .75rem; }
.icon-btn {
  width: 36px; height: 36px; min-height: 36px; display: grid; place-items: center; padding: 0; cursor: pointer;
  color: var(--fg-soft); background: transparent; border: 1px solid var(--line); border-radius: 10px;
}
.icon-btn:hover { color: var(--fg); }
:root[data-theme='dark'] .i-sun, :root[data-theme='light'] .i-moon { display: none; }
#exit { min-height: 36px; padding: 0 .85rem; border: 1px solid var(--line); border-radius: 10px; background: transparent; color: var(--fg-soft); cursor: pointer; }
#exit:hover { color: var(--fg); }

main { padding-bottom: 4rem; }
.panel, #gate, dialog { border: 1px solid var(--line); border-radius: 18px; background: var(--panel); }
.panel { padding: clamp(18px, 3vw, 36px); }

#gate { max-width: 30rem; margin: clamp(3rem, 12vh, 7rem) auto 0; padding: clamp(24px, 4vw, 40px); }
#gate h1 { font-size: clamp(24px, 4vw, 30px); line-height: 1.1; margin-bottom: 1.25rem; }
#google-button { min-height: 44px; color-scheme: light; }
#gate ~ #notice:not(:empty) { max-width: 30rem; margin: 1rem auto 0; }

nav { display: inline-flex; margin: .5rem 0 1.25rem; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--panel); }
nav button { min-height: 40px; padding: 0 1.1rem; border: 0; border-radius: 0; background: none; color: var(--muted); cursor: pointer; }
nav button + button { border-left: 1px solid var(--line); }
nav button:hover { color: var(--fg); }
nav button[aria-current] { background: var(--fg); color: var(--bg); }

#notice:not(:empty) {
  margin: 0 0 1rem; padding: .7rem 1rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); color: var(--fg-soft); font-size: 14px;
}

.intro { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; }
#desk h1 { font-size: clamp(24px, 3.4vw, 34px); line-height: 1.05; }
#desk h1:focus { outline: none; }
.hint { color: var(--muted); font-size: 14px; margin-top: 1rem; }

button, input, select, textarea { font: inherit; color: inherit; }
button {
  min-height: 44px; max-width: 100%; padding: .5rem 1.1rem; cursor: pointer; font-weight: 500;
  border: 1px solid var(--line); border-radius: 10px; background: transparent;
}
@media (hover: hover) { button:not(:disabled):hover { border-color: var(--accent); } }
button:disabled { opacity: .55; cursor: not-allowed; }
.primary, .primary:not(:disabled):hover { background: var(--fg); border-color: var(--fg); color: var(--bg); }
.danger { color: var(--danger); }
.danger:not(:disabled):hover { border-color: var(--danger); }
.danger.primary, .danger.primary:not(:disabled):hover { background: var(--danger); border-color: var(--danger); color: var(--bg); }
:focus-visible { outline: 2px solid var(--fg); outline-offset: 3px; }
.skip { position: absolute; left: -100vw; top: 0; z-index: 9; padding: .7rem 1rem; background: var(--fg); color: var(--bg); font: 400 12px/1 var(--mono); }
.skip:focus { left: .5rem; top: .5rem; }

form, .fields, fieldset { display: grid; gap: 1rem; min-width: 0; }
form { margin-top: 1.25rem; }
fieldset { margin: 0; padding: clamp(.75rem, 2vw, 1rem); border: 1px solid var(--line-soft); border-radius: 12px; }
legend { padding: 0 .3rem; margin-left: -.3rem; font-size: 13px; }
.row { display: grid; gap: .4rem; }
.row > span { color: var(--muted); }
input:not([type='checkbox']), select, textarea {
  width: 100%; min-width: 0; min-height: 44px; padding: .6rem .8rem; font: 400 15px/1.5 var(--sans);
  color: var(--fg); background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
input:not([type='checkbox']):focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { min-height: 7.5rem; resize: vertical; max-width: 100%; }
.check { display: flex; gap: .6rem; align-items: center; min-height: 44px; }
.check input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }
.settings { max-width: 36rem; }
.actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }

.filter { width: min(15rem, 100%); margin: 1.25rem 0 .25rem; }
.group { margin-top: 1.5rem; }
.group h2 { display: flex; justify-content: space-between; padding: 0 0 .6rem; border-bottom: 1px solid var(--line); color: var(--fg-soft); font-weight: 700; }
ul { margin: 0; padding: 0; list-style: none; }
.item { display: grid; gap: .75rem; padding: 1rem 0; border-bottom: 1px solid var(--line-soft); }
.item:last-child { border-bottom: 0; }
.item strong { display: block; font: 700 15.5px/1.35 var(--mono); letter-spacing: -.02em; }
.meta { display: block; margin-bottom: .3rem; color: var(--muted); }
.summary { margin-top: .3rem; color: var(--fg-soft); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row-actions { display: flex; gap: .5rem; }
.row-actions button { min-height: 36px; padding: .3rem .85rem; font-size: 13.5px; }

dialog {
  width: min(48rem, calc(100% - 1.5rem)); max-height: calc(100dvh - 1.5rem); overflow: auto;
  color: var(--fg); padding: clamp(20px, 3vw, 32px);
}
dialog.compact { max-width: 30rem; }
dialog h2 { font-size: clamp(20px, 2.6vw, 24px); }
dialog .actions { justify-content: flex-end; }
dialog::backdrop { background: rgba(12, 12, 24, .6); }
.feedback:not(:empty) { color: var(--danger); font-size: 14px; }
.feedback:empty { display: none; }
.change { padding: .8rem 0; border-top: 1px solid var(--line-soft); }
.change h3 { font-size: 13px; }
.change p { margin-top: .2rem; color: var(--fg-soft); white-space: pre-wrap; }
dialog form > .actions:last-child {
  --pad: clamp(20px, 3vw, 32px);
  position: sticky; bottom: calc(-1 * var(--pad)); z-index: 1;
  margin: 0 calc(-1 * var(--pad)) calc(-1 * var(--pad)); padding: 1rem var(--pad);
  background: var(--panel); border-top: 1px solid var(--line);
}

.history { margin-top: 1.25rem; }
.history li + li { border-top: 1px solid var(--line-soft); }
.history button { width: 100%; text-align: left; border: 0; border-radius: 10px; padding: .85rem .75rem; }
.history small { display: block; margin-top: .2rem; color: var(--muted); }
.turn { padding: 1rem 0; border-top: 1px solid var(--line-soft); }
.turn h2 { color: var(--muted); font: 400 11px/1.4 var(--mono); letter-spacing: .14em; text-transform: uppercase; }
.turn p { margin: .3rem 0 .9rem; white-space: pre-wrap; color: var(--fg-soft); }

.assist { display: grid; gap: .5rem; }
.assist .actions button { min-height: 40px; padding-inline: .9rem; }
.assist-note:empty { display: none; }
.assist-note { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; color: var(--fg-soft); font-size: 14px; }
.small { min-height: 34px; padding: .25rem .8rem; font-size: 13.5px; }
input.changed, textarea.changed { border-color: var(--accent); }

@media (max-width: 30rem) { .assist .actions button { flex: 1 1 100%; } }
@media (min-width: 40rem) {
  .item { grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 1.5rem; }
  .fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
