/* Wordle-like Number Lock UI */
* { box-sizing: border-box; }

:root {
  --bg: #121213;
  --tile-bg: #121213;
  --tile-border: #3a3a3c;
  --text: #d7dadc;
  --muted: #9aa0a6;
  --tile-size-active: 72px;    /* active row tile size */
  --tile-size-past: 56px;      /* past/future rows tile size */
  --caret-size: 40px;          /* caret button size */
  --tile-gap: 10px;
  --radius: 8px;
  --accent: #6aaa64;           /* correct */
  --present: #c9b458;          /* present */
  --absent: #787c7e;           /* absent */
  --button-bg: #2f2f31;
  --button-hover: #3a3a3c;
  --button-border: #3a3a3c;
  --focus: #8ab4f8;
  /* Legend and highlight hues */
  --hue-red: #ef4444;
  --hue-yellow: #f59e0b; /* orange-yellow */
  --hue-green: #22c55e;
}

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  line-height: 1.4;
  display: flex;
  flex-direction: column;
}

.app-header {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--tile-border);
  position: relative;
  padding: 0 16px;
}
.title {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* Legend to the right of the board */
.legend {
  display: grid;
  grid-template-columns: auto auto auto;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
  color: var(--muted);
  font-size: 12px;
  margin-top: 8px;
}
.legend-item { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.swatch { width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--tile-border); display: inline-block; }
.swatch-red { background: var(--hue-red); }
.swatch-yellow { background: var(--hue-yellow); }
.swatch-green { background: var(--hue-green); }

.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 28px 16px 140px; /* extra space for bottom ad */
  gap: 16px;
  position: relative;
}

/* Keep content away from fixed side ads on wide screens */
@media (min-width: 900px) {
  .app-main { padding-left: 200px; padding-right: 200px; }
}

/* Wrapper around the board and legend */
.board-area {
  display: flex;
  /* [gutter] [board] [legend] [gutter] */
  /* grid-template-columns: 1fr auto 1fr minmax(160px, 240px); */
  align-items: start;
  /* column-gap: clamp(8px, 4vw, 28px); */
  width: 100%;
}

.board-area > .board { grid-column: 2; }
/* .board-area > .legend { grid-column: 4; } */

.board {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;

  min-width: calc(
    var(--reserve-left)
    + (var(--code-length) * var(--tile-size-active))
    + ((var(--code-length) - 1) * var(--tile-gap))
    + var(--reserve-right)
  );
}
.board--blurred { filter: blur(5px); pointer-events: none; }

.row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

/* Grid that holds tiles or carets. JS sets grid-template-columns per row. */
.digits {
  display: grid;
  gap: var(--tile-gap);
}

/* Tiles */
.tile {
  width: var(--tile-size-row, var(--tile-size-past));
  height: var(--tile-size-row, var(--tile-size-past));
  border: 2px solid var(--tile-border-color, var(--tile-border));
  background: var(--tile-bg);
  color: var(--text);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: clamp(24px, 6vw, 36px);
  border-radius: var(--radius);
  user-select: none;
  text-align: center;
  transition: border-color 150ms ease, box-shadow 180ms ease;
}
.tile.colored { box-shadow: 0 0 0 1px var(--tile-border-color, transparent); }
.tile.past, .tile.empty { font-size: clamp(18px, 5vw, 28px); }

.tile:focus { outline: 3px solid var(--focus); outline-offset: 2px; }
/* Keep focus-like highlight even when a hidden input holds focus on mobile */
.tile.mobile-focus { outline: 3px solid var(--focus); outline-offset: 2px; }

/* State colors for optional feedback */
.tile.correct { background: var(--accent); border-color: var(--accent); color: #fff; }
.tile.present { background: var(--present); border-color: var(--present); color: #fff; }
.tile.absent  { background: var(--absent);  border-color: var(--absent);  color: #fff; }

/* Active row digits + submit */
.lock-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr; /* [timer] [digits panel] [submit] */
  align-items: center;
  gap: 16px;
  width: 100%;
}
/* Column wrapper to align up/down carets with digits */
.lock-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  justify-self: center; /* keep panel centered regardless of side elements */
}

.timer-badge {
  justify-self: end;
  background: var(--button-bg);
  border: 2px solid var(--button-border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 9999px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 72px;
  text-align: center;
}
.timer-badge[aria-live] { /* no special styles, semantic hint */ }

.submit-button {
  justify-self: start;
  background: var(--button-bg);
  border: 2px solid var(--button-border);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 9999px;
  font-weight: 700;
  cursor: pointer;
}
.submit-button:hover { background: var(--button-hover); }
.submit-button:focus { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Caret buttons */
.caret {
  width: var(--caret-size);
  height: var(--caret-size);
  border-radius: 9999px;
  border: 1px solid var(--button-border);
  background: var(--button-bg);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  line-height: 1; /* better vertical centering for glyphs on mobile */
  user-select: none;
  justify-self: center;
  align-self: center;
  -webkit-appearance: none;
  appearance: none;
}
.caret .caret-icon { width: 60%; height: 60%; display: block; }
.caret:hover { background: var(--button-hover); }
.caret:focus { outline: 2px solid var(--focus); outline-offset: 2px; }

.hint {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.end-message {
  display: none;
  margin-top: 12px;
  color: var(--text);
  max-width: 820px;
  text-align: center;
  font-size: 18px;
  line-height: 1.6;
  white-space: pre-line;
}
.end-message.visible { display: block; }
.end-message.win { color: var(--hue-green); }
.end-message.lose { color: var(--hue-red); }

/* Overlay start */
.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content:center;
  pointer-events: none; /* only button is interactive */
  z-index: 10;
  padding-bottom: 300px;
}
.overlay.visible { display: flex; }
.start-button {
  pointer-events: auto;
  padding: 14px 24px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 9999px;
  border: 2px solid var(--button-border);
  background: var(--button-bg);
  color: var(--text);
  cursor: pointer;
}
.start-button:hover { background: var(--button-hover); }
.start-button:focus { outline: 3px solid var(--focus); outline-offset: 3px; }

/* Ad placeholders */
.ad { position: fixed; background: #2b2b2b; opacity: 0.9; z-index: 5; }
.ad-left { top: 56px; bottom: 96px; left: 0; width: 180px; }
.ad-right { top: 56px; bottom: 96px; right: 0; width: 180px; }
.ad-bottom { left: 0; right: 0; bottom: 0; height: 96px; }

/* Hide side ads on narrow screens */
@media (max-width: 900px) {
  .ad-left, .ad-right { display: none; }
  .app-main { padding-bottom: 120px; }
}

/* Confetti */
.confetti-layer { position: fixed; inset: 0; pointer-events: none; z-index: 20; overflow: hidden; }
.confetti { position: absolute; width: 8px; height: 12px; opacity: 0.95; border-radius: 2px; bottom: 0; animation-name: confetti-fly; }
.confetti.from-left { left: 0; }
.confetti.from-right { right: 0; }

@keyframes confetti-fly {
  0%   { transform: translate(0, 0) rotate(0deg); opacity: 1; }
  100% { transform: translate(var(--dx, 240px), var(--dy, -800px)) rotate(var(--rot, 1080deg)); opacity: 0; }
}

/* Subtle pop animation when colors apply */
@keyframes tile-pop {
  0% { transform: scale(0.96); }
  70% { transform: scale(1.06); }
  100% { transform: scale(1); }
}
/* .tile.colored { box-shadow: 0 0 0 1px var(--tile-border-color, transparent); animation: tile-pop 160ms ease-out; animation-delay: var(--pop-delay, 0ms); } */

/* Responsive tweaks */

@media (max-width: 750px) {
  :root { --tile-size-active: 42px; --tile-size-past: 34px; --caret-size: 26px; --tile-gap: 8px; }
  .submit-button { padding: 5px 8px; font-size: 14px; }
  .timer-badge { padding: 5px 18px; min-width: 50px; font-size: 14px; }
  /* Center the active row and reduce side spacing */
  .lock-row { width: auto; margin-left: auto; margin-right: auto; grid-template-columns: 50px auto 50px; justify-content: center; column-gap: 12px; }
  .digits { justify-content: center; }
}


@media (max-width: 460px) {
  :root { --tile-size-active: 35px; --tile-size-past: 28px; --caret-size: 24px; --tile-gap: 6px; }
  .submit-button { padding: 4px 8px; font-size: 13px; }
  .timer-badge { padding: 4px 8px; min-width: 50px; }
  /* Slightly tighten columns on very small screens */
  .lock-row { column-gap: 10px; }
}


/* colored animates; colored-done is the static final state */
.tile.colored {
  box-shadow: 0 0 0 1px var(--tile-border-color, transparent);
  animation: tile-pop 160ms ease-out;
  animation-delay: var(--pop-delay, 0ms);
}

.tile.colored-done {
  box-shadow: 0 0 0 1px var(--tile-border-color, transparent);
  /* no animation */
}

/* Offscreen input used to trigger mobile keyboards */
.visually-hidden-input {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  /* Prevent iOS auto-zoom on small font-size inputs */
  font-size: 16px;
}

/* Base size (desktop) */
.tile.active,
.active-tile {
  font-size: 2.25rem; /* 20px if root is 16px */
  line-height: 1.2;
}

@media (max-width: 750px) {
  .tile.active,
  .active-tile {
    font-size: 1.4rem; /* 15px */
  }
}

