:root {
  --panel:     #ffffff;
  --ink:       #4a3421;
  --ink-soft:  #7a6248;
  --line:      #4a3421;
  --line-soft: #d8cdb9;

  --good-bg:   #d6ecd2;
  --good-txt:  #2e5d2e;
  --bad-bg:    #f4d4d4;
  --bad-txt:   #8b3a3a;
  --win-bg:    #f2fdf0;
  --button-bg: #fffa;

  /* Layout metrics */
  --app-width: 30rem;
  --cell:      3rem;
  --cell-gap:  .4rem;
  --score-w:   2.5rem;

  /* Initial height of the board, in guess rows. */
  --board-min-rows: 5;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }


html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}
body {
    overflow: hidden;
    color: var(--ink);
    font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    background-color: rgb(206 201 187);
    background-image: radial-gradient(rgb(240 230 211) 0.6138px, transparent 0.6138px), radial-gradient(rgb(233 232 231) 0.6138px, transparent 0.6138px);
    background-size: 8.184px 8.184px, 8.184px 8.184px;
    background-repeat: repeat, repeat;
    background-position: 0px 0px, 4.092px 4.092px;
}
/* ---------- App shell ---------- */

.app {
  height: 90dvh;
  max-width: var(--app-width);
  margin: 5dvh auto;
  /* Bottom margin: one line of text between Reveal and the viewport edge. */
  padding: 0 .75rem 1.5rem;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 2px solid var(--ink);
  border-radius: 1rem;
    --spacing: 1mm;
    --lineWidth: 1px;
    --c1: #fcf5c154;
    --c2: #f9ebba70;
    --c3: #47443b2b;
    --c4: #00000047;
    --c5: #fff0;
    --c6: #ded6b83d;
    --c7: #e9ddcb94;
    --c8: #f8f2c95c;
    background-image: repeating-linear-gradient(0deg, var(--c1) 0px, var(--c6) var(--lineWidth), var(--c7) var(--lineWidth), var(--c8) var(--spacing)), repeating-linear-gradient(45deg, var(--c2) 0px, var(--c3) var(--lineWidth), var(--c4) var(--lineWidth), var(--c5) var(--spacing));
    background-position: 0px 0px;
    background-color: #ffffff;
    background-size: 1cm 1cm;
    animation-name: bodyAnim;
    animation-duration: 3s;
    animation-iteration-count: infinite;
    animation-timing-function: linear;
}

/* ---------- Header ---------- */

.site-header {
  flex: 0 0 auto;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: .9rem 0;
  border-bottom: 2px solid var(--line);
}

.site-header h1 {
  margin: 0;
  font-size: 1.4rem;
  letter-spacing: .1em;
  font-weight: normal;
}

.header-actions {
  display: flex;
  align-items: baseline;
  gap: .4rem;
}

.header-btn {
  font: inherit;
  font-size: .78rem;
  padding: .28rem .65rem;
  border: 1.5px solid var(--line);
  border-radius: 4px;
  background-color: var(--button-bg);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.header-btn:hover:not(:disabled) { background: rgba(74,52,33,.08); }
.header-btn:disabled { opacity: .45; cursor: default; }

/* ---------- Alphabet ---------- */

.alphabet {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(13, 1fr);
  gap: .3rem;
  padding: .8rem 0;
  border-bottom: 2px solid var(--line);
}

.letter {
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: 0;
  font: inherit;
  font-size: .9rem;
  line-height: 1;
  border: 1.5px solid var(--line);
  border-radius: 6px;
  background: var(--button-bg);
  color: var(--ink);
  cursor: pointer;
  transition: background .12s, color .12s;
}
.letter:hover { background: rgba(74,52,33,.08); }
.letter:focus-visible { outline: 2px solid var(--ink-soft); outline-offset: 2px; }

.letter[data-state="1"] { background: var(--bad-bg);  color: var(--bad-txt); }
.letter[data-state="2"] { background: var(--good-bg); color: var(--good-txt); font-weight: bold; }

/* ---------- Play area ---------- */

.play {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-top: 1rem;
}

/* Only the board scrolls.  It starts at --board-min-rows tall, grows
   naturally with content, and shrinks (scrolls) once the dock below
   has run out of room. */
.board {
  flex: 0 1 auto;
  min-height: calc(
    var(--board-min-rows) * (var(--cell) + var(--cell-gap))
    - var(--cell-gap)
  );
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--cell-gap);
}

/* Every row uses the same track sizes, so all cells align into a grid. */
.row {
  position: relative;
  display: grid;
  grid-template-columns: repeat(5, var(--cell)) var(--score-w);
  gap: var(--cell-gap);
  justify-content: center;
  flex-shrink: 0;
}

.cell {
  position: relative;
  width: var(--cell);
  height: var(--cell);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.7rem;
  line-height: 1;
  text-transform: lowercase;
  border: 2px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  user-select: none;
  transition: background .2s ease, color .2s ease;
}

.cell.active::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2px;
  height: 55%;
  transform: translate(-50%, -50%);
  background: var(--ink-soft);
  animation: blink 1.1s step-end infinite;
}

@keyframes blink {
  0%, 50%      { opacity: 1; }
  50.01%, 100% { opacity: 0; }
}

.row .score {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding-left: 2rem;
  font-size: 1.5rem;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.row .score.conflict {
  color: var(--bad-txt);
}

/* Transparent input stretched over the input row. */
.guess-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: transparent;
  caret-color: transparent;
  opacity: 0;
  font: inherit;
  font-size: 16px;
  outline: none;
}

.cell.win {
  background: var(--win-bg) !important;
  color: var(--good-txt);
  font-weight: bold;
}
/* Letter marked red on the alphabet — matches across all guesses. */
.cell.marked-out {
  background: var(--bad-bg);
  color: var(--bad-txt);
}

/* Letter marked green on the alphabet — matches across all guesses. */
.cell.marked-in {
  background: var(--good-bg);
  color: var(--good-txt);
  font-weight: bold;
}

/* ---------- Bottom dock ---------- */

.bottom-dock {
  flex: 0 0 auto;
  padding-top: var(--cell-gap);
  display: flex;
  flex-direction: column;
  gap: .7rem;
}

.message {
  text-align: center;
  min-height: 1.4em;
  margin: 0;
  font-size: .9rem;
}
.message.error  { color: var(--bad-txt); }
.message.win    { color: var(--good-txt); font-weight: bold; }
.message.reveal { color: var(--ink-soft); }

.reveal-wrap {
  display: flex;
  justify-content: center;
}

.reveal-btn {
  font: inherit;
  font-size: .82rem;
  padding: .35rem 1.1rem;
  border: 1.5px solid var(--line);
  border-radius: 4px;
  background-color: var(--button-bg);
  color: var(--ink);
  cursor: pointer;
}
.reveal-btn:hover:not(:disabled) { background: rgba(74,52,33,.08); }
.reveal-btn:disabled { opacity: .4; cursor: default; }

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(74, 52, 33, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fade-in .15s ease-out;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 8px;
  width: 100%;
  max-width: 28rem;
  max-height: 85dvh;
  overflow-y: auto;
  padding: 1.1rem 1.4rem 1.4rem;
  animation: rise-in .18s ease-out;
}

@keyframes rise-in {
  from { transform: translateY(.6rem); opacity: 0; }
  to   { transform: translateY(0);     opacity: 1; }
}

.modal-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: .75rem;
}
.modal-head h2 {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: .08em;
  font-weight: normal;
}

.modal-close {
  font: inherit;
  font-size: 1.3rem;
  line-height: 1;
  width: 1.9rem;
  height: 1.9rem;
  border: 1.5px solid var(--line);
  border-radius: 4px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.modal-close:hover { background: rgba(74,52,33,.08); }

.modal-body { font-size: .9rem; line-height: 1.5; }
.modal-body p  { margin: 0 0 .8em; }
.modal-body ul { margin: 0 0 .8em; padding-left: 1.2em; }
.modal-body li { margin-bottom: .25em; }

.modal-body code {
  font-family: inherit;
  background: rgba(74,52,33,.08);
  padding: 0 .3em;
  border-radius: 3px;
}

.modal-body kbd {
  font-family: inherit;
  font-size: .85em;
  border: 1px solid var(--line-soft);
  border-bottom-width: 2px;
  border-radius: 3px;
  padding: 0 .35em;
}

/* ---------- Small screens ---------- */

@media (max-width: 480px) {
  :root {
    --cell:    2.4rem;
    --score-w: 2rem;
  }
  .app { padding: 0 .5rem 1.2rem; }
  .alphabet { gap: .2rem; }
  .letter { font-size: .72rem; border-width: 1px; border-radius: 4px; }
  .cell { font-size: 1.3rem; border-width: 1.5px; }
  .row .score { font-size: 1.2rem; }
  .header-btn { font-size: .7rem; padding: .22rem .5rem; }
}

.play-again-wrap {
  display: flex;
  justify-content: center;
}

.play-again-btn {
  font: inherit;
  font-size: .95rem;
  letter-spacing: .05em;
  height: var(--cell);
  padding: 0 2rem;
  border: 2px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}
.play-again-btn:hover { background: rgba(74,52,33,.08); }
.play-again-btn:focus-visible {
  outline: 2px solid var(--ink-soft);
  outline-offset: 2px;
}
