:root {
  --bg: #f6e3cf;
  --bg-hi: #fdf1e1;
  --bg-lo: #eccfb2;
  --ink: #4a2f22;
  --ink-soft: #7a5a48;
  --sheet: #fffaf2;
  --accent: #c4623f;
  --accent-dark: #a54c2c;
  --gold: #f2b632;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  font-family: "Baloo 2", ui-rounded, system-ui, sans-serif;
  color: var(--ink);
  background: radial-gradient(ellipse 100% 70% at 50% 25%, var(--bg-hi), transparent 75%), var(--bg);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

button { font: inherit; color: inherit; }

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: calc(var(--sg-corner-top) - 6px) 14px calc(var(--safe-bottom) + 12px);
  max-width: 560px;
  margin: 0 auto;
}

.top {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  min-height: 56px;
}
.title { text-align: center; line-height: 1.05; }
.title h1 { margin: 0; font-size: clamp(24px, 7vw, 30px); font-weight: 800; }
.title p { margin: 2px 0 0; font-size: 14px; font-weight: 600; color: var(--ink-soft); }
.icon-btn {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(74, 47, 34, 0.09);
  cursor: pointer;
}
.icon-btn svg, .ctl svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-btn:focus-visible, .ctl:focus-visible, .primary:focus-visible, .secondary:focus-visible, .daily:focus-visible, .level-btn:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

.status {
  margin: 4px 0 8px;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink-soft);
}

.stage {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  position: relative;
}
#board {
  display: block;
  touch-action: none;
  border-radius: 22px;
  box-shadow: 0 18px 36px -18px rgba(90, 50, 20, 0.55);
  cursor: pointer;
}

.tip {
  margin: 8px 6px 0;
  text-align: center;
  font-size: 15px;
  line-height: 1.3;
  font-weight: 600;
  color: var(--ink-soft);
}

.bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 12px;
}
.ctl {
  min-height: 52px;
  border: 0;
  border-radius: 16px;
  background: rgba(74, 47, 34, 0.09);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s;
}
.ctl b {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  border-radius: 11px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
}
.ctl:active:not(:disabled) { transform: scale(0.95); }
.ctl:disabled { opacity: 0.45; cursor: default; }
.ctl.pulse { animation: nudge 0.5s ease; }
@keyframes nudge { 30% { transform: scale(1.08); } }

.toast {
  position: fixed;
  left: 50%;
  top: 22%;
  transform: translate(-50%, 12px);
  width: max-content;
  max-width: calc(100vw - 48px);
  padding: 10px 16px;
  border-radius: 14px;
  background: rgba(74, 47, 34, 0.95);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 60;
}

/* Sheets */
.sheet {
  width: min(340px, calc(100vw - 32px));
  border: 0;
  border-radius: 26px;
  padding: 22px 22px 20px;
  background: var(--sheet);
  color: var(--ink);
  box-shadow: 0 24px 60px -20px rgba(60, 30, 10, 0.6);
  text-align: center;
}
.sheet.wide { width: min(400px, calc(100vw - 24px)); text-align: left; max-height: calc(100dvh - 28px); overflow-y: auto; overscroll-behavior: contain; }
.sheet::backdrop { background: rgba(60, 30, 14, 0.45); }
.sheet[open] { animation: sheet-in 0.28s cubic-bezier(0.3, 1.3, 0.5, 1); }
@keyframes sheet-in {
  from { opacity: 0; transform: translateY(16px) scale(0.96); }
  to { opacity: 1; transform: none; }
}
.sheet h2 { margin: 0; font-size: 28px; font-weight: 800; line-height: 1.1; }
.sheet p { margin: 6px 0 16px; font-size: 17px; color: var(--ink-soft); }
.sheet .primary + .secondary, .sheet .secondary + .secondary { margin-top: 10px; }

.primary, .secondary {
  width: 100%;
  min-height: 52px;
  border-radius: 16px;
  font-size: 18px;
  font-weight: 700;
  text-decoration: none;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.primary { border: 0; background: var(--accent); color: #fff; }
.secondary { border: 2px solid rgba(74, 47, 34, 0.2); background: transparent; color: var(--ink); }

.win-scene { height: 150px; margin: -8px -6px 0; }
.win-scene svg { width: 100%; height: 100%; display: block; }
.win-ach {
  list-style: none;
  margin: -6px 0 14px;
  padding: 10px 12px;
  border-radius: 16px;
  background: #fff1cc;
  text-align: left;
  font-size: 15px;
}
.win-ach li + li { margin-top: 4px; }
.win-ach b { color: var(--ink); }
.win-ach li.win-wool { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.win-ach .try-wool { width: auto; min-height: 44px; padding: 0 14px; font-size: 15px; border-radius: 12px; background: #fff; }
.win-ach .try-wool:disabled { color: #2b7a53; border-color: #3c9a6c; }

/* The title screen's picture: Kento's scarf (scarf.js) */
.title-scarf { width: 100%; height: 150px; }
.title-scarf svg { width: 100%; height: 100%; display: block; }
/* The Wool Basket sheet */
.basket { text-align: left; }
.basket-scarf { height: 130px; margin: -2px 0 0; border-radius: 16px; background: linear-gradient(#fbe7cc, #f3cfa8); }
.basket-scarf svg { width: 100%; height: 100%; display: block; }
.basket .basket-note { margin: 8px 2px 4px; font-size: 15px; line-height: 1.35; }
.basket h3 { margin: 16px 0 4px; font-size: 17px; font-weight: 800; color: var(--ink); }
.wool-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; margin-top: 8px; }
.wool-tile {
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 76px; padding: 6px 4px 7px;
  border: 2px solid rgba(74, 47, 34, 0.12); border-radius: 13px; background: #fff8ee; color: var(--ink); cursor: pointer;
  box-shadow: inset 0 -3px 0 rgba(74, 47, 34, 0.07);
}
.wool-tile canvas { width: 100%; max-width: 100px; height: auto; aspect-ratio: 200 / 92; }
.wool-tile[aria-pressed="true"] { border-color: #3c9a6c; background: #eef8f2; }
.wool-tile:disabled { background: rgba(255, 248, 238, 0.5); cursor: default; box-shadow: none; }
.wool-tile:disabled canvas { opacity: 0.55; }
.wool-tile:active:not(:disabled) { transform: scale(0.96); }
.wool-name { font-size: 13px; font-weight: 700; line-height: 1.1; text-align: center; }
.wool-tile:disabled .wool-name { color: var(--ink-soft); }

/* Title screen: the shared layout (shared/mainmenu.js); these are only Cat's Cradle's colors. */
#mm {
  --sg-bg: radial-gradient(ellipse 100% 70% at 50% 25%, var(--bg-hi), transparent 75%), var(--bg);
  --sg-ink: var(--ink); --sg-ink-soft: var(--ink-soft);
  --sg-title: var(--accent-dark); --sg-title-shadow: 0 2px 0 #fff;
  --sg-accent: var(--accent); --sg-accent-ink: #fff;
  --sg-card: #fff; --sg-card-ink: var(--ink); --sg-line: rgba(74, 47, 34, 0.18);
}
.sg-sheet { --sg-sheet-bg: var(--sheet); --sg-sheet-ink: var(--ink); --sg-accent: var(--accent); --sg-accent-ink: #fff; --sg-ink-soft: var(--ink-soft); }
.sheet .note, #ach-box > .note { font-size: 15px; margin: 6px 0 0; line-height: 1.35; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }
.sheet-actions.one { grid-template-columns: 1fr; }
.menu-section { margin-top: 0; }

.daily {
  width: 100%;
  min-height: 60px;
  margin: 10px 0 4px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(135deg, #ffe3a3, #f7c35a);
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  text-align: left;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
}
.daily small { display: block; font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.daily .tick { font-size: 22px; }

.pack-head { display: flex; justify-content: space-between; align-items: baseline; margin: 16px 0 6px; }
.pack-head h3 { margin: 0; font-size: 20px; font-weight: 800; }
.pack-head span { font-size: 14px; font-weight: 700; color: var(--ink-soft); }
.level-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.level-btn {
  min-height: 48px;
  border: 0;
  border-radius: 12px;
  background: #f3e8da;
  display: grid;
  place-items: center;
  align-content: center;
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}
.level-btn small { font-size: 11px; color: #d3a21f; margin-top: 1px; }
.level-btn.done { background: #dff0e0; }
.level-btn.next { background: #ffe3a3; }
.level-btn.here { outline: 3px solid var(--accent); outline-offset: -3px; }

.ach-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.ach {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 14px;
  background: #f3ece3;
}
.ach.earned { background: #fff1cc; }
.ach-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #d9cfc3;
  color: #fff;
  font-size: 20px;
  font-weight: 800;
}
.ach.earned .ach-icon { background: linear-gradient(160deg, #ffe58a, #f2b632 55%, #d98a12); }
.ach b { display: block; font-size: 16px; line-height: 1.15; }
.ach span { display: block; font-size: 14px; line-height: 1.25; color: var(--ink-soft); }
.how { margin: 0; padding-left: 20px; font-size: 15px; line-height: 1.35; color: var(--ink-soft); }
.how li + li { margin-top: 4px; }

@media (max-height: 700px) {
  .top { min-height: 48px; }
  .status { margin: 0 0 4px; font-size: 15px; }
  .bar { margin-top: 8px; }
  .ctl { min-height: 48px; }
  .tip { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .ctl, .toast { transition: none; }
  .sheet[open], .ctl.pulse { animation: none !important; }
}

/* iPhone: no double-tap zoom anywhere. touch-action isn't inherited, so it goes on every element
   (anything with its own touch-action keeps it). Text fields stay selectable. */
* { touch-action: manipulation; }
input, textarea { -webkit-user-select: text; user-select: text; }
