/* Keystone — styles */
:root {
  --bg: #141414;
  --card: #1e1e1e;
  --tile: #2a2a2a;
  --tile-sel: #46464a;
  --text: #eaeaea;
  --muted: #9a9a9a;
  --line: #333;
  --c0: #e8b64c; /* amber */
  --c1: #7fc68b; /* mint */
  --c2: #6fa8e8; /* sky */
  --c3: #b48fe0; /* lavender */
  --hub: #f0e6c8;
  --tile-text: #eaeaea;
  --solved-text: #16161a;
}
:root.light {
  --bg: #f2efe9;
  --card: #ffffff;
  --tile: #e4e0d8;
  --tile-sel: #b8b4ac;
  --text: #1c1c1c;
  --muted: #6a6a6a;
  --line: #ddd;
  --tile-text: #1c1c1c;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 12px 32px;
  transition: background .3s, color .3s;
}

/* header */
.site-head { text-align: center; margin-bottom: 6px; }
.logo { display: flex; gap: 6px; justify-content: center; margin-bottom: 4px; }
.lb { width: 22px; height: 22px; border-radius: 6px; display: inline-block; }
.lb.c0 { background: var(--c0); } .lb.c1 { background: var(--c1); }
.lb.c2 { background: var(--c2); } .lb.c3 { background: var(--c3); }
.brandmark { margin: 2px 0; font-size: 1.9rem; font-weight: 800; letter-spacing: .35em; text-indent: .35em; }
.tagline { margin: 2px 0 0; color: var(--muted); font-size: .85rem; }

/* mode bar */
.modebar { display: flex; gap: 8px; margin: 12px 0; }
.modebtn {
  background: var(--card); color: var(--text); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 18px; font-size: .9rem; cursor: pointer;
}
.modebtn.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.modebtn.gear { padding: 6px 12px; }

/* cards */
main { width: 100%; max-width: 420px; }
.card {
  background: var(--card); border-radius: 18px; padding: 16px;
  border: 1px solid var(--line);
  margin-bottom: 14px;
}
.puzzhead { display: flex; justify-content: space-between; color: var(--muted); font-size: .85rem; margin-bottom: 8px; }

/* solved categories */
.solvedlist { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.solvedcat {
  border-radius: 10px; padding: 7px 12px; font-size: .82rem;
  color: var(--solved-text); font-weight: 600;
  animation: slidein .4s ease;
}
.solvedcat span { font-weight: 400; opacity: .8; }
@keyframes slidein { from { transform: translateY(-6px); opacity: 0; } to { transform: none; opacity: 1; } }

/* board */
.board {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  margin: 8px 0 14px;
}
.tile {
  position: relative;
  background: var(--tile); color: var(--tile-text);
  border: 2px solid transparent; border-radius: 12px;
  min-height: 72px; padding: 6px;
  font-size: .78rem; font-weight: 700; letter-spacing: .04em;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; text-align: center;
  transition: background .25s, border-color .25s, transform .15s, color .25s, opacity .3s, order 0s;
  word-break: break-word;
}
.tile:active { transform: scale(.96); }
.tile.sel { background: var(--tile-sel); border-color: var(--text); }
.tile.locked { cursor: default; }
.tile.cat0 { background: var(--c0); color: var(--solved-text); }
.tile.cat1 { background: var(--c1); color: var(--solved-text); }
.tile.cat2 { background: var(--c2); color: var(--solved-text); }
.tile.cat3 { background: var(--c3); color: var(--solved-text); }
.tile.hubrev {
  background: var(--hub); color: #222;
  border-color: #d9a53a;
  box-shadow: 0 0 14px rgba(232, 182, 76, .55);
  animation: hubglow 2.4s ease-in-out infinite;
}
.tile.hubrev.sel, .tile.sel.cat0, .tile.sel.cat1, .tile.sel.cat2, .tile.sel.cat3 {
  border-color: var(--text);
  transform: scale(.96);
}
@keyframes hubglow {
  0%, 100% { box-shadow: 0 0 10px rgba(232,182,76,.35); }
  50% { box-shadow: 0 0 20px rgba(232,182,76,.7); }
}
.tile.shake { animation: shake .45s ease; }
@keyframes shake {
  0% { transform: translateX(0); } 20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); } 60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); } 100% { transform: translateX(0); }
}
.tile.pop { animation: pop .45s ease; }
@keyframes pop {
  0% { transform: scale(1); } 40% { transform: scale(1.12); } 100% { transform: scale(1); }
}
:root.rmotion .tile, :root.rmotion .solvedcat { animation: none !important; }

/* controls */
.controls { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.ctl {
  background: transparent; color: var(--text);
  border: 1px solid var(--muted); border-radius: 999px;
  padding: 8px 16px; font-size: .88rem; cursor: pointer;
}
.ctl:hover:not(:disabled) { border-color: var(--text); }
.ctl.primary { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 700; }
.ctl:disabled { opacity: .35; cursor: default; }

.mistakes { text-align: center; margin-top: 12px; color: var(--muted); font-size: .85rem; }
.mistakes i {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  background: var(--muted); margin-left: 6px; opacity: .4;
}
.mistakes i.lost { opacity: 1; background: #e06060; }

/* toast */
.toast {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%) translateY(-8px);
  background: var(--text); color: var(--bg);
  border-radius: 999px; padding: 8px 20px; font-size: .9rem; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* end card */
.endcard { text-align: center; }
.keystone-reveal { margin: 10px 0 16px; }
.kr-word {
  display: inline-block; font-size: 1.6rem; font-weight: 800; letter-spacing: .12em;
  background: var(--hub); color: #222; border-radius: 12px; padding: 10px 22px;
  box-shadow: 0 0 18px rgba(232,182,76,.5);
}
.kr-sub { color: var(--muted); font-size: .85rem; margin: 10px 0 6px; }
.kr-meanings { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 5px; }
.kr-meanings li {
  border-radius: 9px; padding: 6px 10px; font-size: .82rem; font-weight: 600;
  color: var(--solved-text);
}
.kr-meanings li.cat0 { background: var(--c0); } .kr-meanings li.cat1 { background: var(--c1); }
.kr-meanings li.cat2 { background: var(--c2); } .kr-meanings li.cat3 { background: var(--c3); }
.scorebox { margin: 14px 0 6px; }
.scorebig { font-size: 2.4rem; font-weight: 800; }
.scorenotes { color: var(--muted); font-size: .8rem; white-space: pre-line; }
.statsrow { display: flex; justify-content: center; gap: 24px; margin: 14px 0; }
.stat b { display: block; font-size: 1.3rem; }
.stat span { color: var(--muted); font-size: .75rem; }
.endbtns { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* free play list */
.freelist { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.freerow {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--tile); border-radius: 10px; padding: 10px 14px;
  cursor: pointer; border: 1px solid transparent;
}
.freerow:hover { border-color: var(--muted); }
.freerow .fr-status { font-size: .8rem; color: var(--muted); }
.freerow .fr-status.won { color: var(--c1); }
.freerow .fr-status.lost { color: #e06060; }
h2 { margin: 4px 0 2px; font-size: 1.1rem; }
.muted { color: var(--muted); font-size: .85rem; margin: 4px 0; }

/* info / intro / how-to-play sections */
.info { width: 100%; max-width: 420px; text-align: left; margin-bottom: 14px; }
.info h1 { margin: 0 0 8px; font-size: 1.25rem; line-height: 1.3; }
.info h2 { margin: 0 0 10px; font-size: 1.1rem; }
.info p { margin: 0 0 4px; line-height: 1.55; font-size: .9rem; color: var(--text); }
.info ol, .info ul { margin: 0 0 10px; padding-left: 20px; line-height: 1.55; font-size: .9rem; }
.info li { margin-bottom: 8px; }
.info .muted { line-height: 1.5; }

/* settings dialog */
.dlg {
  background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: 16px; padding: 20px 24px;
}
.dlg::backdrop { background: rgba(0,0,0,.55); }
.setrow { display: block; margin: 10px 0; font-size: .95rem; cursor: pointer; }
#settingsClose { margin-top: 10px; }

.site-foot { color: var(--muted); font-size: .75rem; margin-top: auto; padding-top: 18px; text-align: center; }
.site-foot a { color: var(--muted); }
.timer { font-variant-numeric: tabular-nums; }
