:root {
  --bg: #0f1420;
  --bg2: #151d2d;
  --card: #1a2130;
  --line: #2a3547;
  --text: #e6edf7;
  --muted: #9aa8c0;
  --gold: #f5b942;
  --green: #4ade80;
  --red: #f87171;
  --yellow: #facc15;
  --radius: 14px;
  --t: 150ms;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  min-height: 100%;
}

.bg-gradient {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 20% 5%, #1f2a3d 0%, transparent 45%),
    radial-gradient(circle at 90% 20%, #162136 0%, transparent 42%),
    linear-gradient(180deg, #111827 0%, #0f1420 100%);
  z-index: -1;
}

.app-shell {
  max-width: 860px;
  margin: 0 auto;
  padding: 10px 12px 124px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin: 4px 0 12px;
}

.wordmark {
  margin: 0;
  font-size: 1.56rem;
  letter-spacing: 0.12em;
  font-weight: 800;
}

.key-glyph {
  color: var(--gold);
}

.tagline {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.day-chip {
  background: #202b3f;
  border: 1px solid #34425a;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.82rem;
  white-space: nowrap;
}

.icon-btn,
.btn {
  border: 1px solid #3b4861;
  background: #233149;
  color: var(--text);
  border-radius: 10px;
  cursor: pointer;
  transition: transform var(--t), border-color var(--t), background var(--t);
}

.icon-btn {
  width: 34px;
  height: 34px;
  font-weight: 700;
}

.icon-btn:hover,
.btn:hover {
  border-color: #607395;
  transform: translateY(-1px);
}

.main-content {
  display: grid;
  gap: 12px;
}

.panel,
.puzzle-card,
.result-panel,
.modal {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.panel {
  padding: 16px;
  color: var(--muted);
}

.puzzle-card {
  padding: 12px;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.tier {
  font-size: 0.9rem;
  color: #d4deef;
}

.status-dot {
  width: 11px;
  height: 11px;
  border-radius: 999px;
  border: 1px solid #506280;
  background: #64748b;
}

.status-dot.active {
  background: var(--gold);
}

.status-dot.solved {
  background: var(--green);
  border-color: #2fb360;
}

.bridge {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
}

.tile {
  min-width: 86px;
  min-height: 48px;
  border-radius: 10px;
  border: 2px solid #3a4862;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0 10px;
  background: #202b3f;
}

.tile.fixed {
  background: #293652;
}

.link-glyph {
  color: #7083a5;
  font-size: 0.9rem;
}

.slot {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 10px;
  border: 1px solid transparent;
}

.slot.selected {
  border-color: #5a6f93;
  background: #1f293f;
}

.slot-box {
  width: 40px;
  height: 48px;
  border: 2px solid #41506a;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.18rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: #151d2d;
  transition: border-color var(--t), transform var(--t);
}

.slot-box.filled {
  border-color: var(--gold);
}

.join-preview {
  margin: 12px 0 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.join-chip {
  font-size: 0.8rem;
  border-radius: 999px;
  padding: 4px 8px;
  border: 1px solid #3e4b63;
  background: #182134;
  color: #c4d0e5;
}

.join-chip.valid {
  border-color: #2f9758;
  color: #9bf2b8;
}

.join-chip.invalid {
  border-color: #b03d3d;
  color: #fecaca;
}

.join-chip.partial {
  color: #8a98b4;
}

.shake {
  animation: shake 250ms linear 1;
}

@keyframes shake {
  0% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  50% { transform: translateX(3px); }
  75% { transform: translateX(-2px); }
  100% { transform: translateX(0); }
}

.card-actions {
  display: flex;
  gap: 8px;
}

.btn {
  padding: 9px 12px;
  font-weight: 700;
}

.btn.primary {
  background: #3d3011;
  border-color: #8f6a1c;
}

.btn.secondary {
  background: #233149;
}

.btn.ghost {
  background: transparent;
  border-color: #2f3c53;
  color: #8b98ad;
  font-weight: 600;
}

.btn.ghost:hover {
  color: var(--text);
  border-color: #607395;
}

.solved-summary {
  display: grid;
  gap: 8px;
}

.pop-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.pop-tile {
  background: #20334b;
  border: 1px solid #3d5170;
  border-radius: 8px;
  padding: 6px 8px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  animation: popin 240ms ease both;
}

.pop-tile.ok {
  border-color: #2f9758;
  background: #173126;
}

@keyframes popin {
  0% { transform: scale(0.92); opacity: 0.3; }
  100% { transform: scale(1); opacity: 1; }
}

.solved-joins {
  color: #9be8b7;
  font-size: 0.9rem;
}

.result-panel {
  padding: 14px;
  display: grid;
  gap: 8px;
}

.result-title {
  margin: 0;
}

.emoji-row {
  font-size: 1.1rem;
  letter-spacing: 0.2em;
}

.result-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.countdown {
  color: #d0dcf0;
  font-size: 0.92rem;
}

.site-footer {
  margin-top: 16px;
  text-align: center;
  color: #a6b2c8;
  font-size: 0.85rem;
}

.site-footer a {
  color: #c9d8f1;
}

.privacy {
  color: #93a4c3;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 108px;
  transform: translateX(-50%) translateY(14px);
  opacity: 0;
  background: #2a3449;
  border: 1px solid #516484;
  color: #eef4ff;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
  transition: opacity var(--t), transform var(--t);
  z-index: 40;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.modal {
  width: min(720px, 94vw);
  color: var(--text);
  padding: 12px;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.steps {
  margin: 8px 0;
  padding-left: 20px;
}

.small-note {
  color: #c4d0e6;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 8px;
}

.stat {
  background: #202b3f;
  border: 1px solid #34445e;
  border-radius: 10px;
  padding: 8px;
}

.stat b {
  display: block;
  font-size: 1.1rem;
}

.histogram {
  margin-top: 10px;
  display: grid;
  gap: 4px;
}

.hist-row {
  display: grid;
  grid-template-columns: 54px 1fr 40px;
  gap: 6px;
  align-items: center;
  font-size: 0.82rem;
}

.bar {
  height: 10px;
  background: #253149;
  border-radius: 999px;
  overflow: hidden;
}

.bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #f5b942, #ef9f32);
}

.archive-list {
  display: grid;
  gap: 6px;
  max-height: 60vh;
  overflow: auto;
}

.archive-item {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 10px;
  border-radius: 10px;
  background: #202b3f;
  border: 1px solid #364661;
  color: #e4ebf8;
  cursor: pointer;
}

.archive-item .flag {
  font-size: 0.82rem;
}

.flag.done {
  color: var(--green);
}

.flag.todo {
  color: #94a3bd;
}

.on-screen-kbd {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(12, 18, 30, 0.95);
  border-top: 1px solid #30405d;
  padding: 6px;
  display: none;
  gap: 6px;
  z-index: 50;
}

.kbd-row {
  display: flex;
  justify-content: center;
  gap: 4px;
}

.kkey {
  flex: 1 1 0;
  min-width: 0;
  padding: 10px 0;
  border-radius: 8px;
  border: 1px solid #475976;
  background: #24324a;
  color: var(--text);
  font-weight: 700;
  font-size: 0.95rem;
}

.kkey.wide {
  flex: 1.7 1 0;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
}

.kbd-row {
  max-width: 460px;
  margin: 0 auto;
  width: 100%;
}

.on-screen-kbd {
  padding: 5px 4px calc(5px + env(safe-area-inset-bottom));
}

@media (max-width: 720px) {
  .bridge {
    flex-wrap: wrap;
    justify-content: center;
    row-gap: 8px;
  }

  .slot-box {
    width: 30px;
    height: 40px;
    font-size: 1rem;
  }

  .tile {
    min-height: 40px;
    padding: 8px 10px;
    font-size: 1rem;
  }

  .link-glyph {
    font-size: 0.9rem;
  }
}

@media (max-width: 480px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .wordmark {
    font-size: 1.35rem;
    letter-spacing: 0.09em;
  }

  .top-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 380px) {
  .slot-box {
    width: 26px;
    height: 36px;
    font-size: 0.95rem;
  }

  .tile {
    min-height: 36px;
    padding: 6px 8px;
    font-size: 0.9rem;
  }
}

@media (pointer: coarse) {
  .on-screen-kbd {
    display: grid;
  }

  body {
    padding-bottom: 190px;
  }
}

.share-fallback {
  width: 100%;
  margin-top: 10px;
  background: #0f1622;
  color: #e8c37a;
  border: 1px solid #2a3446;
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: 0.9rem;
  resize: vertical;
}

/* "Also from AI Village" reciprocal link row */
.also-from{
  margin-top:14px;
  padding-top:10px;
  border-top:1px solid rgba(255,255,255,0.07);
  display:flex;
  flex-wrap:wrap;
  justify-content:center;
  align-items:baseline;
  gap:4px 14px;
  font-size:0.74rem;
  line-height:1.5;
}
.also-from-label{color:#7c889c;letter-spacing:0.02em;}
.also-from a{color:#9aa7bd;text-decoration:none;border-bottom:1px solid rgba(154,167,189,0.28);}
.also-from a:hover{color:#e8c96a;border-bottom-color:#e8c96a;}
.also-from a span{color:#6c7789;border:0;}
@media (max-width:480px){
  .also-from{flex-direction:column;align-items:center;gap:6px;}
  .also-from a span{display:none;}
}

.more-play {
  margin-top: 18px;
  padding: 16px 18px 18px;
  border: 1px dashed #2a3446;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.02);
  text-align: center;
}

.more-play-copy {
  margin: 0 0 12px;
  color: #8b98ad;
  font-size: 0.92rem;
}


.yesterday {
  margin: 22px auto 0;
  max-width: 520px;
  border: 1px solid #2a3446;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.02);
  padding: 0 16px;
}
.yesterday summary {
  cursor: pointer;
  padding: 14px 0;
  font-weight: 700;
  color: var(--gold);
  font-size: 0.98rem;
  list-style: none;
}
.yesterday summary::-webkit-details-marker { display: none; }
.yesterday summary::before {
  content: '\25b8';
  display: inline-block;
  margin-right: 8px;
  transition: transform 0.15s ease;
}
.yesterday[open] summary::before { transform: rotate(90deg); }
.yesterday-note {
  margin: 0 0 14px;
  color: #8b98ad;
  font-size: 0.85rem;
}
.yesterday-row {
  padding: 12px 0;
  border-top: 1px solid #232c3c;
}
.yesterday-bridge {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  row-gap: 6px;
  margin: 8px 0 6px;
}
.y-tile {
  padding: 5px 9px;
  border-radius: 8px;
  background: var(--slate);
  border: 1px solid var(--border);
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
}
.y-tile.key {
  color: var(--gold);
  border-color: rgba(245, 185, 66, 0.55);
  background: rgba(245, 185, 66, 0.08);
}
.y-link { color: #5c6a80; font-size: 0.8rem; }
.yesterday-joins {
  text-align: center;
  color: #4abe80;
  font-size: 0.82rem;
  letter-spacing: 0.03em;
}
.yesterday-play {
  display: inline-block;
  margin: 14px 0 18px;
  color: #8b98ad;
  font-size: 0.88rem;
  text-decoration: none;
  border-bottom: 1px solid #2f3c53;
}
.yesterday-play:hover { color: var(--text); border-color: #607395; }

.result-nudge {
  margin: 10px 0 0;
  color: #8b98ad;
  font-size: 0.88rem;
}

.bridge-seg {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.stuck-nudge {
  margin: 12px 0 0;
  color: #8b98ad;
  font-size: 0.85rem;
  line-height: 1.45;
}

.day-progress {
  margin: 0 0 14px;
  color: #f5b942;
  font-size: 0.9rem;
  font-weight: 600;
  text-align: center;
  letter-spacing: 0.01em;
}

.install-btn{display:block;margin:14px auto 0}

.install-hint{margin:12px 0 0;color:#8b98ad;font-size:.85rem}

.howto-start{display:block;width:100%;margin:18px 0 0;padding:13px 16px;font-size:1rem}
