/* Catppuccin Macchiato */
:root {
  --base: #24273a;
  --mantle: #1e2030;
  --crust: #181926;
  --surface0: #363a4f;
  --surface1: #494d64;
  --surface2: #5b6078;
  --overlay0: #6e738d;
  --overlay1: #8087a2;
  --text: #cad3f5;
  --subtext0: #a5adcb;
  --green: #a6da95;
  --yellow: #eed49f;
  --red: #ed8796;
  --blue: #8aadf4;
  --mauve: #c6a0f6;
  --lavender: #b7bdf8;
  --peach: #f5a97f;
  --teal: #8bd5ca;
}

/* Catppuccin Latte (light theme) */
:root[data-theme="light"] {
  --base: #eff1f5;
  --mantle: #e6e9ef;
  --crust: #dce0e8;
  --surface0: #ccd0da;
  --surface1: #bcc0cc;
  --surface2: #acb0be;
  --overlay0: #9ca0b0;
  --overlay1: #8c8fa1;
  --text: #4c4f69;
  --subtext0: #6c6f85;
  --green: #40a02b;
  --yellow: #df8e1d;
  --red: #d20f39;
  --blue: #1e66f5;
  --mauve: #8839ef;
  --lavender: #7287fd;
  --peach: #fe640b;
  --teal: #179299;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }
html { scroll-behavior: smooth; }
body {
  background: var(--base);
  color: var(--text);
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, Menlo, Consolas, monospace;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100dvh;
}

header {
  width: 100%;
  max-width: 520px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--surface0);
}
header h1 { font-size: 1.3rem; letter-spacing: 0.2em; color: var(--lavender); }
header .tux { letter-spacing: normal; }
header nav { display: flex; gap: 6px; }

.icon-btn {
  background: var(--surface0);
  color: var(--text);
  border: none;
  border-radius: 8px;
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  font-size: 0.9rem;
  cursor: pointer;
  font-family: inherit;
}
.icon-btn:hover { background: var(--surface1); }

#tabs {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

#viewing-banner {
  width: 100%;
  max-width: 520px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  padding: 8px 12px;
  background: var(--mantle);
  border: 1px solid var(--surface1);
  border-radius: 8px;
  font-size: 0.8rem;
  color: var(--subtext0);
}
#viewing-banner button {
  background: var(--surface0);
  color: var(--text);
  border: 1px solid var(--surface1);
  border-radius: 6px;
  padding: 6px 10px;
  font-family: inherit;
  font-size: 0.75rem;
  cursor: pointer;
  white-space: nowrap;
}
.tab {
  background: var(--surface0);
  color: var(--subtext0);
  border: none;
  border-radius: 8px 8px 0 0;
  padding: 8px 16px;
  cursor: pointer;
  font-family: inherit;
}
.tab.active { background: var(--surface1); color: var(--text); }
.tab#tab-pro { color: var(--peach); }

main {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 16px 8px calc(16px + env(safe-area-inset-bottom));
  flex: 1;
}

/* Board */
#board {
  display: grid;
  gap: 6px;
}
.row { display: grid; gap: 6px; grid-auto-flow: column; }
.tile {
  width: min(58px, 12.5vw);
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.2rem, 5vw, 1.8rem);
  font-weight: 700;
  text-transform: uppercase;
  border: 2px solid var(--surface1);
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  transition: transform 0.08s;
}
.tile.filled { border-color: var(--overlay0); transform: scale(1.04); }
.tile.correct { background: var(--green); border-color: var(--green); color: var(--crust); }
.tile.present { background: var(--yellow); border-color: var(--yellow); color: var(--crust); }
.tile.absent  { background: var(--surface1); border-color: var(--surface1); color: var(--subtext0); }
.tile.reveal { animation: flip 0.4s ease; }
@keyframes flip { 0% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
.row.shake { animation: shake 0.3s; }
@keyframes shake { 20%,60% { transform: translateX(-5px); } 40%,80% { transform: translateX(5px); } }

/* Locked pro puzzle overlay */
#locked-msg {
  text-align: center;
  background: var(--mantle);
  border: 1px solid var(--surface1);
  border-radius: 12px;
  padding: 24px 18px;
  max-width: 340px;
}
#locked-msg .primary { margin-top: 12px; }

/* Hints */
#hints { display: flex; gap: 8px; }
.hint-btn {
  background: var(--surface0);
  border: 1px solid var(--surface1);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-family: inherit;
  position: relative;
}
.hint-btn .hint-label { font-weight: 700; font-size: 0.85rem; }
.hint-btn .hint-sub { font-size: 0.65rem; color: var(--subtext0); }
.hint-btn:disabled, .hint-btn.locked { opacity: 0.4; }
.hint-btn.available { border-color: var(--teal); box-shadow: 0 0 8px rgba(139, 213, 202, 0.35); }
.hint-btn.available::after {
  content: "hint available";
  position: absolute;
  top: -9px;
  right: -6px;
  background: var(--teal);
  color: var(--crust);
  font-size: 0.55rem;
  padding: 1px 6px;
  border-radius: 8px;
  white-space: nowrap;
}
.hint-btn.used { border-color: var(--overlay0); box-shadow: none; }
.hint-btn.used::after { content: none; }

/* Keyboard */
#keyboard { display: flex; flex-direction: column; gap: 6px; width: 100%; max-width: 500px; margin-top: auto; }
.kb-row { display: flex; gap: 5px; justify-content: center; }
.key {
  flex: 1;
  max-width: 44px;
  height: 52px;
  background: var(--surface1);
  color: var(--text);
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  touch-action: manipulation;
}
.key.wide { max-width: 68px; flex: 1.6; font-size: 0.7rem; }
.key:active { background: var(--surface2); }
.key.correct { background: var(--green); color: var(--crust); }
.key.present { background: var(--yellow); color: var(--crust); }
.key.absent { background: var(--surface0); color: var(--overlay0); }

#footnote { font-size: 0.7rem; color: var(--overlay0); line-height: 1.6; }
#footnote a { color: var(--subtext0); }

/* Toast */
#toast {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--crust);
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.9rem;
  z-index: 50;
}

/* Modals */
dialog {
  background: var(--mantle);
  color: var(--text);
  border: 1px solid var(--surface1);
  border-radius: 14px;
  padding: 22px;
  max-width: min(92vw, 420px);
  width: 100%;
  margin: auto;
  font-family: inherit;
}
dialog::backdrop { background: rgba(24, 25, 38, 0.75); }
dialog h2 { color: var(--lavender); margin-bottom: 10px; }
dialog h3 { color: var(--subtext0); margin: 14px 0 6px; font-size: 0.9rem; }
dialog p { font-size: 0.9rem; line-height: 1.5; margin-bottom: 8px; }
dialog ul { margin: 8px 0 14px 20px; font-size: 0.9rem; line-height: 1.7; }
dialog .close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  color: var(--subtext0);
  font-size: 1.4rem;
  cursor: pointer;
}
.modal-actions { display: flex; gap: 8px; margin: 12px 0; flex-wrap: wrap; }

button.primary, a.primary {
  background: var(--mauve);
  color: var(--crust);
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button.primary:hover, a.primary:hover { background: var(--lavender); }
dialog button:not(.close):not(.primary) {
  background: var(--surface0);
  color: var(--text);
  border: 1px solid var(--surface1);
  border-radius: 8px;
  padding: 10px 18px;
  font-family: inherit;
  cursor: pointer;
}

#result-answer {
  background: var(--crust);
  border-radius: 8px;
  padding: 10px;
  text-align: center;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--green);
  margin-bottom: 10px;
}
#learn-more { color: var(--blue); font-size: 0.85rem; display: block; margin-bottom: 8px; }
.countdown { color: var(--subtext0); font-size: 0.8rem !important; }
.archive-cta {
  background: none !important;
  border: none !important;
  color: var(--mauve) !important;
  font-size: 0.85rem !important;
  padding: 8px 0 0 !important;
  margin-top: 6px;
  width: 100%;
  text-align: center;
  border-top: 1px solid var(--surface1) !important;
  font-weight: 600;
}
.archive-cta:hover { color: var(--lavender) !important; }

.help-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; font-size: 0.85rem; }
.help-link { color: #00b6ba; font-size: 0.85rem; display: block; margin-top: 4px; }
.tile.demo { width: 34px; font-size: 1rem; }

/* Stats */
#stats-numbers { display: flex; gap: 10px; justify-content: space-between; text-align: center; }
.stat { flex: 1; }
.stat .num { font-size: 1.6rem; font-weight: 700; color: var(--lavender); }
.stat .label { font-size: 0.6rem; color: var(--subtext0); }
.dist-row { display: flex; align-items: center; gap: 8px; margin: 4px 0; font-size: 0.8rem; }
.dist-bar {
  background: var(--surface1);
  border-radius: 4px;
  padding: 2px 8px;
  min-width: 24px;
  text-align: right;
  font-weight: 700;
}
.dist-bar.top { background: var(--green); color: var(--crust); }

/* Archive */
#archive-month {
  background: var(--surface0);
  color: var(--text);
  border: 1px solid var(--surface1);
  border-radius: 8px;
  padding: 8px;
  font-family: inherit;
  margin-bottom: 12px;
  width: 100%;
}
#archive-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 6px; }
.arch-cell {
  border-radius: 8px;
  padding: 8px 4px;
  text-align: center;
  font-size: 0.7rem;
  background: var(--surface0);
  color: var(--subtext0);
  border: 1px solid var(--surface1);
  cursor: pointer;
}
.arch-cell:hover { border-color: var(--lavender); }
.arch-cell .day { font-size: 1rem; font-weight: 700; color: var(--text); }
.arch-cell.solved { background: rgba(166, 218, 149, 0.18); border-color: var(--green); }
.arch-cell.failed { background: rgba(237, 135, 150, 0.18); border-color: var(--red); }
.arch-cell.pro { border-style: dashed; }

/* Account / pro */
#login-form { display: flex; gap: 8px; flex-wrap: wrap; }
#login-form input {
  flex: 1;
  min-width: 180px;
  background: var(--crust);
  border: 1px solid var(--surface1);
  color: var(--text);
  border-radius: 8px;
  padding: 10px;
  font-family: inherit;
}
.price-line { font-size: 1.05rem !important; }
.strike { text-decoration: line-through; color: var(--overlay0); }
#pro-price, .price-line #pro-price { color: var(--green); font-weight: 700; font-size: 1.3rem; }
.badge {
  background: var(--peach);
  color: var(--crust);
  font-size: 0.6rem;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 700;
  vertical-align: middle;
}

/* Help / doc page */
.doc-header {
  width: 100%;
  max-width: 640px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--surface0);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.doc-header a { color: var(--subtext0); text-decoration: none; font-size: 0.85rem; }
.doc-header a:hover { color: var(--text); }
.doc {
  width: 100%;
  max-width: 640px;
  padding: 20px 16px 48px;
  line-height: 1.6;
}
.doc h1 { color: var(--lavender); font-size: 1.6rem; letter-spacing: 0.05em; margin-bottom: 6px; }
.doc > p.lede { color: var(--subtext0); margin-bottom: 24px; }
.doc h2 { color: var(--lavender); font-size: 1.15rem; margin: 30px 0 10px; border-bottom: 1px solid var(--surface0); padding-bottom: 6px; scroll-margin-top: 20px; }
.doc h3 { color: var(--teal); font-size: 0.95rem; margin: 16px 0 4px; }
.doc p { margin-bottom: 10px; font-size: 0.9rem; }
.doc ul, .doc ol { margin: 8px 0 14px 20px; font-size: 0.9rem; }
.doc li { margin-bottom: 4px; }
.doc a { color: var(--blue); }
.doc code { background: var(--surface0); border-radius: 4px; padding: 1px 5px; font-size: 0.85em; }
.doc table { width: 100%; border-collapse: collapse; margin: 10px 0 18px; font-size: 0.85rem; }
.doc th, .doc td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--surface0); }
.doc th { color: var(--subtext0); }
.doc .cat { box-sizing: border-box; width: 100%; text-align: left; background: var(--mantle); border: 1px solid var(--surface1); border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; }
.doc .cat h3 { margin-top: 0; }
.doc .cat .examples { color: var(--subtext0); font-size: 0.85rem; margin-bottom: 4px; }

/* Table of contents — desktop only, fixed alongside the centered doc column */
#toc { display: none; }
@media (min-width: 1200px) {
  #toc {
    display: block;
    position: fixed;
    top: 90px;
    left: max(16px, calc(50% - 524px));
    width: 180px;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
  }
  #toc .toc-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--overlay0);
    margin-bottom: 10px;
  }
  #toc ul { list-style: none; display: flex; flex-direction: column; gap: 6px; }
  #toc a {
    display: block;
    color: var(--subtext0);
    text-decoration: none;
    font-size: 0.8rem;
    line-height: 1.3;
    padding: 4px 0 4px 10px;
    border-left: 2px solid var(--surface1);
  }
  #toc a:hover { color: var(--text); border-left-color: var(--teal); }
}

.hidden { display: none !important; }

@media (max-width: 380px) {
  .tile { width: 13vw; }
  .key { height: 46px; }
}

@media (min-width: 700px) {
  /* On desktop the viewport is much taller than the content, so pinning
     the keyboard to the bottom via margin-top:auto leaves a big gap.
     Keep it close under the hints instead; mobile keeps the bottom pin
     for thumb reach. */
  #keyboard { margin-top: 24px; }
}
