/*
 * Pencil sketch design system for the Playground.
 * White paper, graphite lines, colour-pencil hatching, hand-drawn font.
 * pencil.js adds the wobble filter (#pencil); without it the outlines are just clean borders.
 * Class names (.card .btn .btn-alt .row .col .out .big .grid .chip .muted .back .tool .tile .c1-.c6)
 * are used by every tool page: keep them.
 */
@font-face {
  font-family: 'Patrick Hand';
  src: url('/fonts/patrick-hand-latin-400-normal.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --ink: #2b2b2b;
  --paper: #ffffff;
  --muted: #6a6a6a;
  --faint: #d9d9d9;
  --c1: #eb7fa8; /* pink pencil */
  --c2: #56a0e0; /* blue */
  --c3: #4cc2a0; /* green */
  --c4: #f2c94c; /* yellow */
  --c5: #a98bdb; /* purple */
  --c6: #f2994a; /* orange */
  --wobble: 26px 12px 28px 14px / 14px 28px 12px 26px;
  --wobble-s: 16px 8px 18px 10px / 10px 18px 8px 16px;
}

* { box-sizing: border-box; }
html { font-size: 18px; }

body {
  margin: 0;
  padding: 0 16px 24px;
  color: var(--ink);
  background-color: var(--paper);
  /* faint notebook lines */
  background-image: linear-gradient(transparent 33px, #edf2f9 34px);
  background-size: 100% 34px;
  font-family: 'Patrick Hand', 'Comic Sans MS', 'Segoe UI', cursive;
  line-height: 1.5;
}

h1, h2, h3 { font-weight: 400; line-height: 1.15; margin: 0 0 8px; }
h1 { font-size: clamp(2.2rem, 7vw, 3.4rem); }
h2 { font-size: 1.8rem; }
h3 { font-size: 1.3rem; }
p { margin: 0 0 8px; }
a { color: var(--ink); }
img { max-width: 100%; }

/* ---------- hand-drawn outlines ---------- */
.card, .out, .tile, .btn, .btn-alt, .chip, a.back, .pill {
  position: relative;
  border: 0;
  border-radius: var(--wobble);
}
.card::before, .out::before, .tile::before, .btn::before, .btn-alt::before, .chip::before, a.back::before, .pill::before {
  content: '';
  position: absolute;
  inset: 0;
  border: 2.5px solid var(--ink);
  border-radius: inherit;
  filter: url(#pencil);
  pointer-events: none;
}
.out::before { border-style: dashed; border-color: #8c8c8c; }
.btn::before, .btn-alt::before, .chip::before, a.back::before, .pill::before { border-width: 2.2px; }
.btn, .btn-alt, .chip, a.back, .pill { border-radius: var(--wobble-s); }
.chip, .pill { border-radius: 999px 40px 999px 40px / 40px 999px 40px 999px; }

/* ---------- layout ---------- */
.tool { max-width: 780px; margin: 0 auto; padding: 8px 4px 24px; }
.tool > h1 { display: flex; align-items: center; gap: 12px; margin: 18px 0 10px; }
.tool-icon { width: 64px; height: 64px; flex: none; filter: url(#pencil); }

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.col { display: flex; flex-direction: column; gap: 10px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 26px; }

.card { background: var(--paper); padding: 18px; margin: 18px 0; }
.out { background: var(--paper); padding: 14px; margin: 12px 0; }
.big { font-size: clamp(2.2rem, 8vw, 3.6rem); line-height: 1.1; }
.muted { color: var(--muted); font-size: 0.9rem; }
label { display: block; color: var(--muted); }
hr { border: 0; border-top: 2px dashed var(--faint); margin: 16px 0; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 6px 8px; text-align: left; border-bottom: 2px dashed var(--faint); }

/* ---------- controls ---------- */
.btn, .btn-alt {
  display: inline-block;
  padding: 9px 20px;
  font: inherit;
  font-size: 1.05rem;
  cursor: pointer;
  color: var(--paper);
  background: var(--ink);
  transition: transform 0.12s ease;
}
.btn-alt { color: var(--ink); background: var(--paper); }
.btn-alt::before { background: repeating-linear-gradient(-45deg, transparent 0 5px, rgb(235 127 168 / 0.35) 5px 7px); }
.btn:hover, .btn-alt:hover { transform: translateY(-2px) rotate(-1deg); }
.btn:active, .btn-alt:active { transform: translateY(1px); }
.btn:disabled, .btn-alt:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.chip {
  display: inline-block;
  padding: 3px 14px;
  font: inherit;
  cursor: pointer;
  color: var(--ink);
  background: var(--paper);
}
.chip.on::before { background: repeating-linear-gradient(-45deg, transparent 0 4px, rgb(76 194 160 / 0.55) 4px 6px); }

input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 2.2px solid var(--ink);
  border-radius: var(--wobble-s);
  padding: 8px 12px;
  max-width: 100%;
}
input[type=range] { padding: 0; border: 0; accent-color: var(--ink); }
input[type=checkbox] { accent-color: var(--ink); width: 1.1rem; height: 1.1rem; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px dashed var(--ink);
  outline-offset: 3px;
}
::placeholder { color: #9a9a9a; }

a.back {
  display: inline-block;
  margin: 18px 0 0;
  padding: 4px 16px;
  text-decoration: none;
}
a.back:hover { transform: rotate(-1deg); }

/* ---------- home page ---------- */
.hero { position: relative; max-width: 900px; margin: 0 auto; padding: 36px 8px 8px; text-align: center; }
.hero h1 { position: relative; display: inline-block; font-size: clamp(2.6rem, 9vw, 4.6rem); }
.hero .mark { text-decoration: underline wavy 3px var(--ink); text-underline-offset: 12px; }
.lead { font-size: 1.3rem; color: var(--muted); margin: 18px 0 10px; }
.pills { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin: 12px 0 18px; }
.pill { padding: 2px 16px; background: var(--paper); }
.hero input[type=text] { width: min(420px, 100%); text-align: center; font-size: 1.1rem; padding: 10px 14px; }
#count { margin-top: 10px; }

.float { position: absolute; width: 56px; height: 56px; pointer-events: none; animation: float 6s ease-in-out infinite; }
.float.slow { animation-duration: 9s; animation-delay: -3s; }
.f1 { left: 2%; top: 30px; }
.f2 { right: 4%; top: 18px; width: 64px; height: 64px; }
.f3 { left: 8%; bottom: 40px; width: 72px; height: 72px; }
.f4 { right: 9%; bottom: 52px; }

main.home { max-width: 1040px; margin: 0 auto; padding: 8px 0 12px; }
.sec { display: flex; align-items: center; gap: 12px; margin: 34px 0 6px; }
.sec img { width: 44px; height: 44px; }
.sec-note { margin: 0 0 16px; }

.tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px 16px;
  text-decoration: none;
  color: var(--ink);
  background: var(--paper);
  transition: transform 0.2s ease;
}
.tile:hover { transform: translateY(-5px) rotate(-0.9deg); }
.tile .art {
  display: grid;
  place-items: center;
  height: 128px;
  margin: 0 0 8px;
  border-radius: 20px 10px 22px 12px / 12px 22px 10px 20px;
  background: repeating-linear-gradient(-45deg, transparent 0 5px, var(--tone) 5px 7px);
}
.tile .art img {
  width: 84px;
  height: 84px;
  padding: 8px;
  border-radius: 50%;
  background: var(--paper);
  filter: url(#pencil);
  transition: transform 0.25s ease;
}
.tile:hover .art img { animation: wiggle 0.6s ease; }
.tile h3 { margin-top: 2px; }
.tile p { color: var(--muted); font-size: 0.95rem; flex: 1; }
.tile .go { text-decoration: underline wavy 1px; text-underline-offset: 4px; }
.tile.c1 { --tone: rgb(235 127 168 / 0.5); }
.tile.c2 { --tone: rgb(86 160 224 / 0.5); }
.tile.c3 { --tone: rgb(76 194 160 / 0.5); }
.tile.c4 { --tone: rgb(242 201 76 / 0.6); }
.tile.c5 { --tone: rgb(169 139 219 / 0.5); }
.tile.c6 { --tone: rgb(242 153 74 / 0.5); }
.tile:hover::before { border-color: #000; }

.site-foot, footer { max-width: 900px; margin: 36px auto 0; padding-top: 16px; border-top: 2px dashed var(--faint); display: flex; gap: 20px; justify-content: center; flex-wrap: wrap; color: var(--muted); }
footer p { margin: 0; }

/* ---------- motion ---------- */
@keyframes float { 0%, 100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-12px) rotate(6deg); } }
@keyframes wiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-9deg); } 75% { transform: rotate(9deg); } }

@media (max-width: 700px) {
  .float { display: none; }
  html { font-size: 17px; }
  .tool-icon { width: 48px; height: 48px; }
}
@media (prefers-reduced-motion: reduce) {
  .float, .tile:hover .art img { animation: none; }
  .tile, .btn, .btn-alt, a.back { transition: none; }
  .tile:hover, .btn:hover, .btn-alt:hover, a.back:hover { transform: none; }
}

/* ---------- phones: bigger touch targets, no accidental zoom ---------- */
@media (max-width: 700px) {
  html { font-size: 17px; }
  input[type=range] { height: 36px; }
  input[type=range]::-webkit-slider-thumb { width: 26px; height: 26px; }
  input[type=range]::-moz-range-thumb { width: 26px; height: 26px; }
  .btn, button { min-height: 44px; }
  input[type=text], input[type=number], select, textarea { font-size: 16px; min-height: 44px; }
  .tool, .play { padding-left: 0; padding-right: 0; }
}

/* ---------- "How to play" box under every game ---------- */
.howto { margin: 22px auto 8px; max-width: 980px; }
.howto h2 { margin-bottom: 6px; }
.howto ol { margin: 6px 0 10px; padding-left: 1.4rem; }
.howto li { margin: 5px 0; }
