:root {
  color-scheme: light;
  --ink: #193d30;
  --deep: #153d2d;
  --green: #2c674b;
  --paper: #f6f5ed;
  --white: #fffef9;
  --muted: #4e6458;
  --line: #d3dbca;
  --pale: #e8efdc;
  --lime: #e1edbb;
  --gold: #926800;
  --grey: #586761;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--paper); color: var(--ink); }
button, input, select { font: inherit; }
button, select, .file-label { cursor: pointer; }
button:disabled { cursor: default; opacity: .54; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid #95630d; outline-offset: 3px; }
a { color: inherit; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.site-header, main {
  width: min(100% - 26px, 904px);
  margin-inline: auto;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 63px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--deep);
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -.06em;
  text-decoration: none;
}

.brand-light { font-weight: 470; }

.quiet, .primary, .text-button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: .86rem;
  font-weight: 650;
  line-height: 1.2;
}

.quiet { color: var(--deep); background: var(--white); border-color: var(--line); }
.primary { color: white; background: var(--deep); }
.text-button { color: var(--muted); background: transparent; text-decoration: underline; text-underline-offset: 3px; }
.connection { padding: 28px 0; }

.toolbar {
  display: grid;
  gap: 8px;
  margin: 12px 0 10px;
}

nav {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 3px;
  padding: 3px;
  background: #e7ebdf;
  border-radius: 11px;
}

nav button {
  min-height: 44px;
  padding: 0 4px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: .85rem;
  font-weight: 670;
}

nav button[aria-pressed="true"] { background: var(--deep); color: white; }

input:not([type="file"]), select {
  min-width: 0;
  min-height: 44px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  color: var(--ink);
  font-size: 1rem;
}

#filter { width: 100%; }
.game-layout { display: grid; gap: 12px; }

.produce-card {
  display: grid;
  grid-template-columns: minmax(90px, 35%) minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--pale);
}

.photo-area {
  display: grid;
  place-items: center;
  height: clamp(94px, 28vw, 124px);
  overflow: hidden;
  border-radius: 8px;
  background: white;
}

.photo-area img { width: 100%; height: 100%; object-fit: contain; }
#photo-fallback { font: 3rem Georgia, serif; color: var(--green); }
.produce-info { min-width: 0; overflow-wrap: anywhere; }
.pill {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 12px;
  background: var(--white);
  color: var(--green);
  font-size: .68rem;
  font-weight: 720;
}
.produce-info h1 { margin: 5px 0 3px; font: 400 clamp(1.35rem, 6vw, 1.75rem)/1.06 Georgia, serif; }
.produce-info p { margin: 3px 0 0; font-size: .8rem; line-height: 1.3; color: var(--muted); }
.produce-info .size-note { font-size: .72rem; }
.produce-info p:empty { display: none; }

.guess-panel { min-width: 0; }
.board-heading {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin: 0 0 8px;
}
.board-heading h2 { margin: 0; font: 400 1.38rem/1.15 Georgia, serif; }
#attempt-label { font-size: .74rem; color: var(--muted); }

#board { display: grid; gap: 4px; width: min(100%, 224px); margin-inline: auto; }
.guess-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.tile {
  display: grid;
  place-items: center;
  height: 33px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--white);
  font-size: 1.22rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}
.tile.filled { border-color: var(--green); }
.tile.current { box-shadow: inset 0 -3px var(--lime); }
.correct { background: var(--green) !important; color: white !important; border-color: var(--green) !important; }
.present { background: var(--gold) !important; color: white !important; border-color: var(--gold) !important; }
.absent { background: var(--grey) !important; color: white !important; border-color: var(--grey) !important; }

.message {
  display: grid;
  place-items: center;
  min-height: 28px;
  margin: 3px 0;
  padding: 2px 0;
  color: var(--muted);
  text-align: center;
  font-size: .79rem;
}
.message.result { color: var(--deep); font-weight: 700; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; max-width: 388px; margin-inline: auto; }
.keypad button {
  min-width: 0;
  min-height: 45px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: #e3eada;
  color: var(--deep);
  font-size: 1.15rem;
  font-weight: 730;
  touch-action: manipulation;
}
.keypad button[data-key="Enter"] { color: white; background: var(--deep); font-size: .86rem; }
.round-actions { display: flex; justify-content: center; align-items: center; min-height: 46px; margin: 3px 0 1px; }
.legend { display: flex; flex-wrap: wrap; gap: 5px 12px; justify-content: center; font-size: .71rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i, .help-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; flex: none; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin: 16px 0 0;
  padding: 12px 0;
  border-block: 1px solid var(--line);
  text-align: center;
}
.stats > div { display: flex; flex-direction: column-reverse; gap: 4px; border-right: 1px solid var(--line); }
.stats > div:last-child { border: 0; }
.stats dt { color: var(--muted); font-size: .76rem; }
.stats dd { margin: 0; font: 1.5rem Georgia, serif; }
footer { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 3px 0 10px; color: var(--muted); font-size: .74rem; }

.study-heading { display: grid; gap: 10px; margin: 16px 0 12px; }
.study-heading h1, dialog h2 { margin: 0; font: 400 1.75rem/1.1 Georgia, serif; }
.deck-tools, .form-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.file-label { position: relative; }
.file-label:focus-within { outline: 3px solid #95630d; outline-offset: 3px; }
.file-label input { opacity: 0; position: absolute; inset: 0; width: 100%; cursor: pointer; }
.file-label:has(input:disabled) { opacity: .54; }
.deck-note { color: var(--muted); font-size: .82rem; line-height: 1.45; }
#deck-message:empty, .form-error:empty { display: none; }
#study-grid { display: grid; gap: 8px; margin-top: 13px; }
.study-card {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--white);
}
.study-thumb { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 5px; background: white; color: var(--green); }
.study-thumb img { height: 100%; width: 100%; object-fit: contain; }
.study-card h3 { margin: 0 0 2px; font-size: .9rem; line-height: 1.2; overflow-wrap: anywhere; }
.study-card p { margin: 0; color: var(--muted); font-size: .76rem; overflow-wrap: anywhere; }
.study-actions { display: flex; align-items: center; gap: 5px; }
.study-actions strong { font-size: 1rem; font-variant-numeric: tabular-nums; letter-spacing: .03em; }
.study-actions .quiet { min-width: 44px; padding-inline: 6px; }

dialog {
  width: min(100% - 20px, 470px);
  max-height: 90dvh;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  color: var(--ink);
}
dialog::backdrop { background: #122e237f; }
dialog h2 { margin: 2px 45px 15px 0; }
dialog p, dialog li { font-size: .9rem; line-height: 1.45; }
dialog form { display: grid; gap: 10px; }
dialog label { display: grid; gap: 4px; min-width: 0; font-size: .85rem; font-weight: 650; }
dialog input, dialog select { width: 100%; }
dialog .deck-note, dialog .form-error { margin: 0; }
.form-row { display: grid; grid-template-columns: 1fr 1.2fr; gap: 8px; }
.form-error { color: #8b351f; }
.close {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font-size: 1.6rem;
}
.help-legend { display: grid; gap: 5px; padding: 0; list-style: none; }
.help-legend li { display: flex; gap: 7px; align-items: baseline; }

@media (min-width: 480px) {
  .toolbar { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
  .toolbar nav { max-width: 390px; }
  .toolbar #filter-wrap { grid-column: 2; }
  .study-heading { grid-template-columns: 1fr minmax(200px, 45%); align-items: center; }
}

@media (min-width: 690px) {
  .site-header { min-height: 76px; }
  .toolbar { margin: 20px 0 16px; }
  .game-layout { grid-template-columns: minmax(0, 1fr) minmax(0, .9fr); gap: clamp(18px, 4vw, 48px); align-items: start; }
  .produce-card { grid-template-columns: 1fr; padding: 14px; gap: 16px; }
  .photo-area { height: clamp(230px, 29vw, 330px); }
  .produce-info { padding: 0 8px 10px; }
  .produce-info h1 { font-size: clamp(1.8rem, 4vw, 2.55rem); }
  .produce-info p { font-size: .9rem; }
  .produce-info .size-note { font-size: .78rem; }
  .board-heading h2 { font-size: 1.65rem; }
  #board { width: 250px; gap: 5px; }
  .tile { height: 40px; }
  .stats { margin-top: 22px; }
  #study-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 320px) and (max-width: 479px) {
  .guess-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(142px, 43%);
    grid-template-areas:
      "heading heading"
      "board keypad"
      "message message"
      "actions actions"
      "legend legend";
    column-gap: 9px;
    align-items: start;
  }
  .board-heading { grid-area: heading; }
  #board { grid-area: board; width: 100%; }
  .keypad { grid-area: keypad; width: 100%; }
  .keypad button { min-height: 51px; }
  .message { grid-area: message; }
  .round-actions { grid-area: actions; }
  .legend { grid-area: legend; }
}
