/* ==========================================================================
   Perimeter Playground — shared style
   Adapted from michaelleung.info/games (dark teal + light blue)
   ========================================================================== */
:root {
  --teal-darkest: #123c3c; --teal-dark: #1a4f4f; --teal-mid: #2b6f6f;
  --accent: #7dc1d1; --accent-soft: #a9d6e1; --accent-tint: #eaf5f8;
  --ink: #17262e; --ink-soft: #4c636d; --line: #dde9ec;
  --paper: #fff; --cream: #f7f4ee; --radius: 18px;
  --shadow: 0 10px 30px rgba(18, 60, 60, 0.10);
  --shadow-hover: 0 18px 44px rgba(18, 60, 60, 0.18);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  font-family: "Segoe UI", "Helvetica Neue", Arial, "Noto Sans", "Microsoft JhengHei", "PingFang TC", sans-serif;
  color: var(--ink); background: var(--paper); line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}
img, svg { max-width: 100%; }
a { color: var(--teal-mid); text-decoration: none; }
a:hover { color: var(--teal-dark); }
.container { width: min(1180px, 92%); margin: 0 auto; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; } /* .overlay/.challenge-list set display:grid — author rules beat the UA [hidden] rule without this */

/* skip link + header */
.skip-link { position: absolute; left: -9999px; top: 0; background: var(--accent); color: var(--teal-darkest); padding: .6rem 1rem; border-radius: 0 0 10px 0; z-index: 200; }
.skip-link:focus { left: 0; }
.site-header { position: sticky; top: 0; z-index: 100; background: var(--teal-darkest); border-bottom: 1px solid rgba(125, 193, 209, 0.18); }
.nav { display: flex; align-items: center; justify-content: space-between; padding: .9rem 0; gap: 1rem; }
.brand { display: flex; align-items: center; gap: .6rem; color: #fff; font-weight: 700; font-size: 1.1rem; }
.brand:hover { color: var(--accent-soft); }
.brand-logo { height: 34px; width: 34px; }
.brand .brand-name { color: var(--accent); }
.brand:hover .brand-name { color: var(--accent-soft); }
.nav-links { display: flex; align-items: center; gap: .4rem; list-style: none; }
.nav-links a { color: #dcebee; font-size: .95rem; padding: .45rem .9rem; border-radius: 999px; transition: background .2s, color .2s; }
.nav-links a:hover { background: rgba(125, 193, 209, 0.15); color: #fff; }
.nav-links a.active { background: var(--accent); color: var(--teal-darkest); font-weight: 600; }
.lang-btn { background: rgba(125,193,209,.16); color: var(--accent-soft); border: 1px solid rgba(125,193,209,.45); border-radius: 999px; padding: .45rem .9rem; font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer; }
.lang-btn:hover { background: rgba(125,193,209,.3); color: #fff; }
.nav-toggle { display: none; background: none; border: 1px solid rgba(125,193,209,.4); color: #fff; border-radius: 10px; padding: .4rem .7rem; font-size: 1.1rem; cursor: pointer; }

/* hero */
.hero { position: relative; overflow: hidden; color: #fff;
  background: radial-gradient(1100px 500px at 50% -10%, rgba(125,193,209,.22), transparent 60%),
              linear-gradient(160deg, var(--teal-darkest) 0%, var(--teal-dark) 55%, #22605f 100%);
  text-align: center; padding: 5rem 0 4.2rem; }
#hero-particles { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; }
.hero-inner { position: relative; z-index: 2; }
.pill { display: inline-block; padding: .4rem 1.1rem; border-radius: 999px; background: rgba(125,193,209,.16); border: 1px solid rgba(125,193,209,.45); color: var(--accent-soft); font-size: .9rem; letter-spacing: .4px; margin-bottom: 1.4rem; }
.hero h1 { font-size: clamp(2.2rem, 5vw, 3.6rem); line-height: 1.15; font-weight: 800; margin-bottom: 1rem; }
.hero h1 .hl { color: var(--accent); }
.hero p.lead { font-size: clamp(1.05rem, 2vw, 1.25rem); color: #cfe4e8; max-width: 720px; margin: 0 auto 1rem; }
.hero p.sub { color: #a9c8cd; max-width: 640px; margin: 0 auto 2.2rem; font-size: .98rem; }
.btn-row { display: flex; gap: .9rem; justify-content: center; flex-wrap: wrap; }
.btn { display: inline-flex; align-items: center; gap: .55rem; padding: .85rem 1.7rem; border-radius: 999px; font-weight: 700; font-size: 1rem; cursor: pointer; transition: transform .15s, box-shadow .2s, background .2s; border: none; font-family: inherit; }
.btn-primary { background: var(--accent); color: var(--teal-darkest); box-shadow: 0 8px 22px rgba(125,193,209,.35); }
.btn-primary:hover { background: var(--accent-soft); transform: translateY(-2px); color: var(--teal-darkest); }
.btn-ghost { background: rgba(255,255,255,.08); color: #fff; border: 1px solid rgba(255,255,255,.35); }
.btn-ghost:hover { background: rgba(255,255,255,.16); transform: translateY(-2px); color: #fff; }
.hero-figure { position: relative; z-index: 2; margin: 3rem auto 0; width: min(860px, 92%); border-radius: 24px; overflow: hidden; box-shadow: 0 30px 60px rgba(0,0,0,.35); border: 1px solid rgba(125,193,209,.25); background: rgba(255,255,255,.04); padding: 1.5rem; }

/* sections */
.section { padding: 4.5rem 0; }
.section.alt { background: var(--cream); }
.section-head { text-align: center; max-width: 760px; margin: 0 auto 3rem; }
.section-label { display: inline-block; font-size: .82rem; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase; color: var(--teal-mid); background: var(--accent-tint); border: 1px solid var(--line); padding: .35rem 1rem; border-radius: 999px; margin-bottom: 1rem; }
.section-head h2 { font-size: clamp(1.7rem, 3.4vw, 2.4rem); font-weight: 800; margin-bottom: .8rem; }
.section-head p { color: var(--ink-soft); }

/* game cards */
.games-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 2rem; }
.game-card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; transition: transform .2s, box-shadow .25s; }
.game-card:hover { transform: translateY(-6px); box-shadow: var(--shadow-hover); }
.game-thumb { position: relative; aspect-ratio: 16/10; overflow: hidden; background: var(--accent-tint); display: grid; place-items: center; }
.game-thumb svg { width: 100%; height: 100%; }
.game-badge { position: absolute; top: 14px; left: 14px; background: rgba(18,60,60,.85); color: var(--accent-soft); font-size: .78rem; font-weight: 700; letter-spacing: .6px; padding: .3rem .8rem; border-radius: 999px; text-transform: uppercase; }
.game-body { padding: 1.6rem 1.7rem 1.8rem; display: flex; flex-direction: column; flex: 1; }
.game-body h3 { font-size: 1.35rem; font-weight: 800; margin-bottom: .5rem; }
.game-body h3 a { color: var(--ink); }
.game-body h3 a:hover { color: var(--teal-mid); }
.game-body p { color: var(--ink-soft); font-size: .96rem; margin-bottom: 1.1rem; }
.tags { display: flex; flex-wrap: wrap; gap: .45rem; margin-bottom: 1.3rem; }
.tag { font-size: .78rem; font-weight: 600; color: var(--teal-mid); background: var(--accent-tint); border: 1px solid var(--line); padding: .25rem .7rem; border-radius: 999px; }
.game-actions { margin-top: auto; display: flex; gap: .7rem; flex-wrap: wrap; }
.btn-play { background: var(--accent); color: var(--teal-darkest); padding: .65rem 1.4rem; font-size: .95rem; }
.btn-play:hover { background: var(--accent-soft); color: var(--teal-darkest); transform: translateY(-2px); }
.btn-learn { background: transparent; color: var(--teal-mid); border: 1px solid var(--line); padding: .65rem 1.2rem; font-size: .95rem; }
.btn-learn:hover { background: var(--accent-tint); color: var(--teal-dark); }

/* why grid + prose */
.why-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.6rem; margin-top: 1rem; }
.why-card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.8rem 1.6rem; box-shadow: var(--shadow); text-align: center; }
.why-icon { width: 54px; height: 54px; margin: 0 auto 1rem; border-radius: 16px; background: var(--accent-tint); border: 1px solid var(--line); display: grid; place-items: center; font-size: 1.5rem; }
.why-card h3 { font-size: 1.08rem; font-weight: 700; margin-bottom: .5rem; }
.why-card p { color: var(--ink-soft); font-size: .92rem; }
.prose { max-width: 820px; margin: 2.5rem auto 0; color: var(--ink-soft); }
.prose h3 { color: var(--ink); font-size: 1.25rem; margin: 1.6rem 0 .6rem; }
.prose p { margin-bottom: 1rem; }
.prose ul { margin: 0 0 1rem 1.2rem; }
.prose li { margin-bottom: .4rem; }

/* ---------- learn page ---------- */
.chapter { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 2rem; margin-bottom: 2rem; }
.chapter h3 { font-size: 1.35rem; font-weight: 800; margin-bottom: .4rem; }
.chapter > p { color: var(--ink-soft); max-width: 720px; }
.formula-card { display: inline-block; background: var(--accent-tint); border: 1px solid var(--line); border-radius: 14px; padding: .7rem 1.2rem; font-weight: 700; color: var(--teal-dark); margin: 1rem 0; font-size: 1.05rem; }
.widget { margin-top: 1.4rem; border-top: 1px dashed var(--line); padding-top: 1.4rem; display: grid; grid-template-columns: minmax(260px, 1fr) minmax(220px, 1fr); gap: 1.6rem; align-items: center; }
.widget .stage { display: grid; place-items: center; }
.widget .panel { display: flex; flex-direction: column; gap: .8rem; }
.widget .run-total { font-size: 1.3rem; font-weight: 800; color: var(--teal-dark); }
.ticks { display: flex; flex-wrap: wrap; gap: .4rem; }
.tick { font-weight: 700; background: var(--accent-tint); border: 1px solid var(--line); border-radius: 10px; padding: .2rem .7rem; color: var(--teal-dark); }
.tick.on { background: var(--accent); color: var(--teal-darkest); }
input[type="range"] { accent-color: var(--teal-mid); width: 100%; }
.side-btn { font: inherit; font-weight: 700; background: var(--accent-tint); color: var(--teal-dark); border: 1px solid var(--line); border-radius: 999px; padding: .3rem .9rem; cursor: pointer; }
.side-btn:hover { background: var(--accent); color: var(--teal-darkest); }
.real-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.2rem; margin-top: 1.2rem; }
.real-card { background: var(--accent-tint); border: 1px solid var(--line); border-radius: 14px; padding: 1.1rem; }
.real-card h4 { font-size: 1rem; margin-bottom: .3rem; }
.real-card p { font-size: .92rem; color: var(--ink-soft); }

/* ---------- game shell (all games) ---------- */
.game-hero { color: #fff; background: radial-gradient(900px 400px at 50% -10%, rgba(125,193,209,.22), transparent 60%), linear-gradient(160deg, var(--teal-darkest), var(--teal-dark)); padding: 3.2rem 0 2.6rem; text-align: center; }
.game-hero h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); font-weight: 800; margin-bottom: .5rem; }
.game-hero p { color: #cfe4e8; max-width: 620px; margin: 0 auto; }
.game-shell { position: relative; max-width: 900px; margin: -1.6rem auto 0; background: var(--paper); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow-hover); padding: 1.8rem; }
.hud { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.hud .stat { font-weight: 700; color: var(--teal-dark); background: var(--accent-tint); border: 1px solid var(--line); border-radius: 999px; padding: .35rem 1rem; font-size: .95rem; }
.timer-track { height: 10px; background: var(--accent-tint); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.timer-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width .25s linear; }
.timer-fill.low { background: #e8a13c; }
.star-toast { position: absolute; top: 16%; left: 50%; transform: translateX(-50%); font-size: 1.5rem; font-weight: 800; color: #b8860b; z-index: 60; pointer-events: none; animation: starpop .9s ease-out forwards; }
@keyframes starpop { 0% { opacity: 0; transform: translate(-50%, 12px); } 30% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -26px); } }
.options-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .8rem; margin-top: 1.4rem; }
.option-btn { font: inherit; font-size: 1.25rem; font-weight: 800; color: var(--teal-dark); background: var(--accent-tint); border: 2px solid var(--line); border-radius: 16px; padding: 1rem; cursor: pointer; transition: transform .12s, background .15s, border-color .15s; }
.option-btn:hover { border-color: var(--teal-mid); transform: translateY(-2px); }
.option-btn.good { background: #d6efdd; border-color: #4d9c66; color: #1e5c33; }
.option-btn.bad { background: #f8dcdc; border-color: #c66; color: #8a2f2f; }
.option-btn .kbd { display: inline-block; font-size: .75rem; font-weight: 600; border: 1px solid var(--line); border-radius: 6px; padding: 0 .4rem; margin-right: .5rem; color: var(--ink-soft); background: #fff; }
.stage-box { display: grid; place-items: center; padding: 1.2rem; background: var(--cream); border: 1px solid var(--line); border-radius: 16px; min-height: 240px; }
.keypad { display: grid; grid-template-columns: repeat(3, 72px); gap: .6rem; justify-content: center; margin-top: 1rem; }
.key { font: inherit; font-size: 1.3rem; font-weight: 700; color: var(--teal-dark); background: var(--accent-tint); border: 1px solid var(--line); border-radius: 12px; padding: .7rem 0; cursor: pointer; }
.key:hover { background: var(--accent); color: var(--teal-darkest); }
.answer-box { font: inherit; font-size: 1.6rem; font-weight: 800; text-align: center; width: 130px; border: 2px solid var(--line); border-radius: 14px; padding: .5rem; color: var(--ink); background: #fff; }
.answer-box.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.overlay { position: absolute; inset: 0; background: rgba(247, 244, 238, .96); border-radius: 24px; display: grid; place-items: center; text-align: center; padding: 2rem; z-index: 40; }
.overlay h2 { font-size: 1.8rem; font-weight: 800; margin-bottom: .6rem; }
.overlay p { color: var(--ink-soft); max-width: 460px; margin: 0 auto 1.4rem; }
.steps { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 1rem 1.4rem; margin: 0 auto 1.2rem; max-width: 460px; text-align: left; }
.steps div { padding: .25rem 0; font-weight: 600; color: var(--teal-dark); }
.stars { font-size: 1.4rem; letter-spacing: 2px; }
.case-stamp { display: inline-block; border: 4px solid #b8860b; color: #b8860b; font-weight: 900; letter-spacing: 3px; border-radius: 10px; padding: .3rem 1rem; transform: rotate(-8deg); margin-bottom: 1rem; }
.mode-row { display: flex; gap: .7rem; justify-content: center; margin-bottom: 1.2rem; flex-wrap: wrap; }
.mode-btn { font: inherit; font-weight: 700; border: 2px solid var(--line); background: #fff; color: var(--teal-mid); border-radius: 999px; padding: .5rem 1.2rem; cursor: pointer; }
.mode-btn.on { background: var(--teal-mid); color: #fff; border-color: var(--teal-mid); }
.challenge-list { display: grid; gap: .6rem; margin-top: 1rem; }
.challenge-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; background: var(--accent-tint); border: 1px solid var(--line); border-radius: 12px; padding: .6rem 1rem; cursor: pointer; }
.challenge-row:hover { border-color: var(--teal-mid); }
.challenge-row .stars { font-size: 1rem; }
.fence-wrap { position: relative; }
#fence-canvas { touch-action: none; width: 100%; height: auto; border-radius: 14px; border: 1px solid var(--line); background: #fbfdfe; cursor: grab; }
.tray { display: flex; align-items: center; justify-content: center; gap: .8rem; margin-top: .9rem; flex-wrap: wrap; }
.tray .seg { width: 46px; height: 18px; border-radius: 9px; background: var(--teal-mid); cursor: grab; }
.hint-text { background: #fffbe6; border: 1px solid #eadfa8; border-radius: 12px; padding: .8rem 1.1rem; color: #6b5d1f; margin-top: 1rem; }

/* footer */
.site-footer { background: var(--teal-darkest); color: #b9d4d9; padding: 3.5rem 0 1.6rem; margin-top: 4.5rem; }
.footer-grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 2.5rem; margin-bottom: 2.5rem; }
.site-footer h4 { color: #fff; font-size: 1rem; margin-bottom: 1rem; }
.site-footer p { font-size: .92rem; max-width: 340px; }
.footer-links { list-style: none; }
.footer-links li { margin-bottom: .55rem; }
.footer-links a { color: #b9d4d9; font-size: .93rem; }
.footer-links a:hover { color: var(--accent); }
.footer-bottom { border-top: 1px solid rgba(125,193,209,.18); padding-top: 1.4rem; text-align: center; font-size: .85rem; color: #8fb3ba; }
.footer-bottom a { color: var(--accent-soft); }

/* a11y + motion + responsive */
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (max-width: 900px) {
  .games-grid, .why-grid, .footer-grid, .real-grid, .widget { grid-template-columns: 1fr; }
  .options-grid { grid-template-columns: 1fr 1fr; }
  .nav-toggle { display: block; }
  .nav-links { display: none; position: absolute; top: 100%; right: 4%; background: var(--teal-darkest); border: 1px solid rgba(125,193,209,.25); border-radius: 14px; padding: .8rem; flex-direction: column; align-items: stretch; box-shadow: var(--shadow-hover); min-width: 210px; }
  .nav-links.open { display: flex; }
  .nav-links a, .nav-links .lang-btn { display: block; text-align: center; width: 100%; }
}
