:root {
  color-scheme: light;
  scrollbar-gutter: stable;
  --paper: #f5f1e8;
  --panel: #fffdf8;
  --ink: #26251f;
  --muted: #645e54;
  --line: #ded7ca;
  --accent: #a53c29;
  --accent-dark: #842c1b;
  --green: #28543d;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.35 system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 280px; height: 100dvh; display: flex; flex-direction: column; }
h2, p { margin: 0; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .7; }
button:focus-visible, input:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
a, .retry { color: var(--accent-dark); }

.site-header, main, .load-status { width: min(100%, 1560px); margin-inline: auto; }
.site-header {
  display: grid; flex: none; grid-template-columns: max-content max-content minmax(0, 1fr);
  align-items: center; min-height: 51px; gap: clamp(6px, 1.4vw, 18px);
  padding: 5px clamp(8px, 2vw, 32px); border-bottom: 1px solid var(--line);
}
.site-brand {
  color: var(--ink); text-decoration: none; display: inline-flex; align-items: center; gap: .33em;
  white-space: nowrap; font-size: clamp(16px, 2.1vw, 24px); font-weight: 800; line-height: 1;
  letter-spacing: -.045em;
}
.site-brand span {
  display: grid; place-items: center; width: 1.5em; aspect-ratio: 1; border-radius: 8px;
  background: var(--accent); color: white; font-size: .85em;
}
.site-actions { display: flex; justify-content: flex-end; align-items: center; gap: 5px; min-width: 0; }
.clock { color: var(--muted); white-space: nowrap; font-size: 12px; line-height: 1.2; }
.clock time { color: var(--ink); font-weight: 750; font-variant-numeric: tabular-nums; }
.help-button, dialog button {
  min-height: 30px; min-width: 30px; padding: 4px 9px; border: 1px solid #c7b7a6;
  border-radius: 8px; background: #f7ede1; color: var(--accent-dark); font-size: 13px; font-weight: 750;
}
.main-nav { display: grid; grid-template-columns: 92px 80px 85px 73px; align-items: center; gap: 5px; min-width: 0; }
.main-nav > a, .main-nav > button, .nav-more summary {
  display: flex; align-items: center; justify-content: center; gap: 5px;
  min-height: 34px; min-width: 0; padding: 4px 7px; border: 1px solid transparent; border-radius: 9px;
  background: #eee6da; color: var(--ink); text-decoration: none; white-space: nowrap;
  font-size: 13px; line-height: 1.15; font-weight: 650;
}
.main-nav > a:hover, .main-nav > button:hover, .nav-more summary:hover,
.nav-more[open] summary { background: #f1ddce; color: var(--accent-dark); }
.main-nav svg {
  width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75;
  stroke-linecap: round; stroke-linejoin: round; color: var(--accent);
}
.nav-more { position: relative; z-index: 12; }
.nav-more summary { list-style: none; cursor: pointer; }
.nav-more summary::-webkit-details-marker { display: none; }
.nav-more-links {
  position: absolute; right: 0; top: calc(100% + 4px); min-width: 174px; display: grid; gap: 2px;
  padding: 5px; border: 1px solid #cbbca9; border-radius: 9px; background: var(--panel);
  box-shadow: 0 6px 18px #39291825;
}
.nav-more-links a, .nav-more-links button {
  display: block; padding: 6px 8px; border: 0; border-radius: 5px; background: transparent; color: var(--ink);
  text-align: left; text-decoration: none; white-space: nowrap; font-size: 12px; font-weight: 650;
}
.nav-more-links :is(a, button):hover { background: #f2e4d3; color: var(--accent-dark); }

main {
  flex: 1; min-height: 0; display: grid;
  grid-template-columns: minmax(0, 1.8fr) minmax(310px, 1fr);
  grid-template-rows: auto minmax(0, 1fr); gap: 8px 12px;
  padding: 0 clamp(10px, 2vw, 32px) max(8px, env(safe-area-inset-bottom));
}
.view, #guess-form, #current, .history, .hint-panel, .result {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; min-width: 0;
}
.view { grid-area: 1 / 1 / 3 / 2; overflow: hidden; display: grid; grid-template-rows: minmax(0, 1fr) auto; min-height: 0; }
.portrait-area { min-height: 0; display: grid; place-items: center; container-type: size; background: #302821; }
.portrait { position: relative; width: min(100cqw, calc(100cqh * 1.136)); aspect-ratio: 568 / 500; }
.portrait > img { display: block; width: 100%; height: 100%; object-fit: contain; }
.portrait-controls { position: absolute; inset: 0; display: grid; grid-template-columns: 1fr 1fr; }
.portrait-controls::after {
  content: ''; position: absolute; top: 0; bottom: 0; left: 50%; width: 1px; background: #ffebcc70; pointer-events: none;
}
.portrait-controls button {
  min-width: 0; display: flex; align-items: end; padding: clamp(5px, 1.25vw, 14px); border: 2px solid transparent;
  background: linear-gradient(transparent 60%, #1f1714a8); color: white;
}
.portrait-controls button:last-child { justify-content: end; }
.portrait-controls button:hover { background: linear-gradient(#f8dfb01c, transparent 50%, #1f1714b0); }
.portrait-controls button[aria-pressed=true] { border-color: #ecaa87; }
.portrait-controls button:focus-visible { outline-color: #ffdfbf; outline-offset: -5px; }
.portrait-controls span {
  border-radius: 5px; border: 1px solid #f9edd895; background: #2e231ee8;
  padding: clamp(3px, .6vw, 7px) clamp(5px, .9vw, 12px); white-space: nowrap;
  font-size: clamp(.67rem, 1.1vw, .87rem); font-weight: 700;
}
.portrait-controls button[aria-pressed=true] span { background: var(--accent); border-color: #f2b396; }
.portrait-controls button.is-solved span { background: var(--green); }
.portrait-footer {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 5px 10px; color: var(--muted); font-size: 12px;
}
.portrait-footer span { color: var(--ink); font-weight: 730; }

#guess-form { grid-area: 1 / 2; position: relative; z-index: 3; }
#guess-form, #current, .history, .hint-panel, .result { padding: 8px 10px; }
.guess-description { text-align: center; }
.guess-description label { font-size: 13px; font-weight: 700; }
.search-wrap { position: relative; display: flex; gap: 6px; margin: 6px 0 2px; }
#query {
  flex: 1; min-width: 0; width: 100%; padding: 8px; border: 1px solid #bcb2a3;
  border-radius: 8px; background: white; color: var(--ink); font-size: 16px;
}
#query::placeholder { color: #756c60; }
.submit { padding: 5px 12px; border: 0; border-radius: 8px; background: var(--accent); color: white; font-weight: 750; }
.submit:hover { background: var(--accent-dark); }
#suggestions {
  position: absolute; top: calc(100% + 4px); inset-inline: 0; z-index: 2; list-style: none;
  max-height: min(26dvh, 200px); overflow: auto; overscroll-behavior: contain; margin: 0;
  padding: 4px; border-radius: 8px; border: 1px solid #cbbca9; background: var(--panel);
  box-shadow: 0 6px 18px #39291825;
}
.suggestion { padding: 6px 8px; min-height: 32px; cursor: pointer; border-radius: 5px; font-size: 14px; }
.suggestion:hover, .suggestion[aria-selected=true] { background: #f2e4d3; }
.feedback { margin-top: 5px; color: var(--muted); font-size: 12px; }
.feedback:empty { display: none; }

.side { grid-area: 2 / 2; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
main:has(#guess-form[hidden]) .side { grid-row: 1 / -1; }
.side:has(.result:not([hidden])) { overflow: auto; }
.side h2 { text-align: center; font-size: 12px; margin-bottom: 4px; }
.progress { padding: 0 8px; display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 12px; }
.progress-label { display: flex; align-items: baseline; gap: 6px; }
.progress-label span { color: var(--muted); white-space: nowrap; }
.steps { display: flex; gap: 3px; align-items: center; list-style: none; margin: 0; padding: 0; text-align: center; }
.steps li { color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; }
.steps [aria-current=step] { background: #f6e5da; border-color: #ca8c77; color: var(--accent-dark); font-weight: 750; }
.steps .step-done { background: #e5efe3; color: var(--green); font-weight: 650; }
.history { display: flex; min-height: 0; flex-direction: column; }
.history-body { min-height: 0; overflow: auto; scrollbar-width: thin; }
#empty { color: var(--muted); font-size: 13px; text-align: center; }
#entries { list-style: none; margin: 0; padding: 0; }
.tip {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(54px, 28%) minmax(65px, auto);
  align-items: center; gap: 6px; padding: 4px 7px; border-bottom: 1px solid #eae3d8;
  font-size: 12px; line-height: 1.24;
}
#current .tip, #entries li:last-child { border-bottom: 0; }
.tip-label { min-width: 0; display: grid; gap: 2px; }
.tip-label strong, .tip-area { overflow-wrap: anywhere; }
.tip-label small, .tip-area { color: var(--muted); }
.tip-status {
  justify-self: end; border-radius: 12px; padding: 3px 7px; background: #efebe4; color: #5a5047;
  text-align: center; font-size: 11px; font-weight: 700;
}
.success-tone { color: var(--green); background: #e5efe3; }
.warm-tone { color: #645100; background: #fff0c5; }
.hot-tone { color: #85401d; background: #fbe2d2; }
.hint-panel { background: #fbf0dd; }
.hint-panel ul { display: grid; gap: 3px; padding-left: 20px; margin: 0; font-size: 12px; }
.result h2 { color: var(--green); font-size: 16px; }
#result-summary { margin: 0 0 6px; color: var(--muted); text-align: center; font-size: 13px; }
#reveals, .reveals { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.reveal { display: grid; gap: 2px; padding: 7px 9px; background: #f3f0e7; border-radius: 6px; }
.reveal strong { font-size: 15px; overflow-wrap: anywhere; }
.reveal small, .reveal span, .reveal p { color: var(--muted); font-size: 12px; }
.reveal p { margin-top: 2px; }
#current .reveal { background: #e5efe3; }
#current .reveal strong { color: var(--green); }

.load-status { padding: 10px clamp(10px, 2vw, 32px); color: var(--muted); }
.retry { padding: 0; border: 0; background: transparent; text-decoration: underline; }
dialog {
  width: min(580px, 92vw); max-height: calc(100dvh - 24px); padding: 14px; overflow: auto;
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--ink); font-size: 14px;
}
dialog::backdrop { background: #241b15a0; }
dialog h2 { margin-bottom: .45rem; font-size: 1.2rem; }
dialog form { margin-top: 8px; }
.help-steps { display: grid; gap: .45rem; margin: .5rem 0; padding-left: 1.25rem; }
.credits, #yesterday-status { color: var(--muted); margin: .45rem 0; font-size: 12px; }
#yesterday-image { display: block; max-width: 100%; max-height: min(38svh, 320px); margin: 0 auto 8px; }

@media (min-width: 741px) and (max-height: 820px) {
  body { height: auto; min-height: 100svh; }
  main {
    flex: none; grid-template-columns: minmax(0, 1fr) minmax(310px, min(35%, 440px));
    grid-template-rows: max-content minmax(0, 1fr); align-content: start; gap: 6px 10px;
  }
  .view { position: sticky; top: 8px; align-self: start; height: max(200px, calc(100svh - 58px)); }
  .side { gap: 6px; }
  #guess-form, #current, .history, .hint-panel, .result { padding: 7px 9px; }
  .search-wrap { margin: 3px 0 2px; }
  #query, .submit { padding-block: 5px; }
}

@media (max-width: 740px) {
  .site-header {
    grid-template-columns: minmax(0, 1fr) auto; min-height: 0; grid-template-rows: 26px 27px;
    gap: 1px 5px; padding: 2px 6px 3px;
  }
  .site-brand { grid-column: 1; grid-row: 1; justify-self: start; }
  .site-actions { grid-column: 2; grid-row: 1; }
  .main-nav {
    grid-column: 1 / -1; grid-row: 2; gap: 3px;
    grid-template-columns: minmax(0, 1.32fr) minmax(0, .8fr) minmax(0, 1.14fr) minmax(0, .79fr);
  }
  .clock { display: grid; text-align: right; font-size: 10px; line-height: 1.15; }
  .help-button { min-height: 24px; min-width: 24px; padding: 1px 4px; }
  .main-nav > a, .main-nav > button, .nav-more summary {
    min-height: 27px; padding: 2px 3px; font-size: clamp(10px, 2.7vw, 12px); gap: 3px;
  }
  .main-nav svg { width: 13px; height: 13px; }
}

@media (max-width: 740px), (max-width: 1000px) and (max-height: 560px) and (pointer: coarse) {
  body { height: auto; min-height: 100svh; }
  main {
    flex: none; grid-template-columns: minmax(0, 1fr); grid-template-rows: none; gap: 6px;
    padding: 0 6px max(10px, env(safe-area-inset-bottom));
  }
  .view, #guess-form, .side, main:has(#guess-form[hidden]) .side { grid-area: auto; }
  .view { position: relative; top: auto; height: clamp(174px, 32svh, 300px); }
  .side { gap: 5px; }
  #guess-form, #current, .history, .hint-panel, .result { padding: 6px 8px; border-radius: 10px; }
  .search-wrap { gap: 4px; margin: 4px 0 0; }
  .guess-description label { font-size: 11px; }
  #query { padding: 5px 7px; }
  .submit { padding: 4px 8px; font-size: 14px; }
  #suggestions { max-height: clamp(64px, calc(100dvh - 88px), 240px); }
  .progress { padding-inline: 3px; font-size: 11px; }
  .tip { padding: 4px 4px; }
}

@media (max-width: 350px) {
  .main-nav svg { width: 11px; height: 11px; }
  .progress-label { gap: 3px; }
  .steps li { padding-inline: 3px; }
}

.main-nav > a[aria-current=page],
.nav-more:has(a[aria-current=page]) summary {
  border-color: #ca8c77;
  background: #f6e5da;
  color: var(--accent-dark);
}
.nav-more-links a[aria-current=page] { color: var(--accent-dark); }
main.info-page {
  display: block;
  flex: none;
  width: min(100%, 680px);
  padding: 8px clamp(10px, 2vw, 32px) max(12px, env(safe-area-inset-bottom));
}
.info-card {
  padding: clamp(12px, 2.5vw, 22px);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
}
.info-card h1 { margin: 0 0 8px; font-size: clamp(20px, 3vw, 28px); }
.info-card > p { color: var(--muted); }
.info-card .play-link { display: inline-block; margin-top: 14px; font-weight: 650; }
#archive-notice { grid-column: 1 / -1; font-size: 13px; padding-block: 4px; }
main:has(#archive-notice:not([hidden])) { grid-template-rows: auto auto minmax(0, 1fr); }
main:has(#archive-notice:not([hidden])) .view { grid-row: 2 / 4; }
main:has(#archive-notice:not([hidden])) #guess-form { grid-row: 2; }
main:has(#archive-notice:not([hidden])) .side { grid-row: 3; }
main:has(#archive-notice:not([hidden])):has(#guess-form[hidden]) .side { grid-row: 2 / 4; }
#comparison, #result-link { display: block; margin-top: 7px; text-align: center; font-size: 13px; }
.main-nav [data-unread] { color: var(--accent-dark); }
.main-nav .friend-badge:not([hidden]) { display: inline-flex; gap: 2px; }
.nav-more-links small:empty { display: none; }
@media (max-width: 740px), (max-width: 1000px) and (max-height: 560px) and (pointer: coarse) {
  main:has(#archive-notice:not([hidden])) { grid-template-rows: none; }
  main:has(#archive-notice:not([hidden])) :is(.view, #guess-form, .side),
  main:has(#archive-notice:not([hidden])):has(#guess-form[hidden]) .side { grid-row: auto; }
}
