html, body { height: 100%; overflow: hidden; }
body { background: radial-gradient(1200px 500px at 0% -10%, var(--accent-soft), transparent 60%), radial-gradient(900px 400px at 100% 110%, var(--accent-soft), transparent 60%), var(--paper); }
.ap { height: 100vh; height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }

/* top bar */
.ap-bar { display: flex; align-items: center; gap: 8px; padding: 10px 12px 0; min-width: 0; }
.ap-home, .ap-icon { display: grid; place-items: center; width: 46px; height: 46px; flex: none; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 3px 0 #e6dccd, 0 6px 14px rgba(70, 40, 15, 0.08); font-size: 20px; text-decoration: none; cursor: pointer; transition: transform 0.12s ease; }
.ap-home:active, .ap-icon:active { transform: translateY(2px); box-shadow: 0 1px 0 #e6dccd; }
.ap-icon[aria-pressed="false"] { opacity: 0.55; }
.ap-icon[hidden] { display: none; }
.ap-title { display: flex; flex-direction: column; min-width: 0; flex: 0 1 auto; padding: 0 4px; }
.ap-title b { color: var(--ink); font: 900 19px/1.1 var(--sans); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -0.01em; }
.ap-title small { color: var(--accent-dark); font: 700 12px/1.3 var(--sans); white-space: nowrap; text-transform: uppercase; letter-spacing: 0.06em; }
.ap-pick { display: flex; align-items: center; gap: 10px; min-height: 52px; min-width: 0; flex: 0 1 380px; padding: 4px 14px 4px 6px; border: 0; border-radius: 26px; background: var(--accent); color: #fff; box-shadow: 0 4px 0 var(--accent-dark), 0 8px 18px rgba(0, 0, 0, 0.12); cursor: pointer; text-align: left; font-family: var(--sans); transition: transform 0.12s ease; }
.ap-pick:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--accent-dark); }
.ap-pick-icon { display: grid; place-items: center; width: 42px; height: 42px; flex: none; border-radius: 50%; background: rgba(255, 255, 255, 0.95); font-size: 22px; color: var(--accent-dark); font-weight: 900; }
.ap-pick-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.ap-pick-text small { font-size: 11px; font-weight: 800; opacity: 0.85; text-transform: uppercase; letter-spacing: 0.06em; }
.ap-pick-text b { font-size: 17px; font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ap-pick-arrow { font-size: 18px; opacity: 0.9; }
.ap-spacer { flex: 1 1 0; }
.ap-tools { display: flex; align-items: center; gap: 8px; flex: none; position: relative; }
.ap-tools .oc-chip { min-height: 46px; border-radius: 23px; padding: 0 12px; font-size: 15px; background: #fff; box-shadow: 0 3px 0 #e6dccd; }
.ap-tools .oc-chip select { max-width: 110px; font-weight: 800; }
.ap-pop { position: absolute; right: 0; top: 56px; z-index: 20; width: min(320px, 92vw); display: grid; gap: 10px; padding: 16px; border-radius: 20px; background: #fff; box-shadow: 0 0 0 1px var(--line), 0 16px 40px rgba(0, 0, 0, 0.16); font-size: 14px; }
.ap-pop[hidden] { display: none; }
.ap-pop label { display: flex; align-items: center; gap: 8px; font-weight: 800; color: var(--ink); }
.ap-pop select { min-height: 40px; border-radius: 12px; border: 0; box-shadow: 0 0 0 2px var(--line); background: #fff; padding: 0 8px; max-width: 200px; font: 700 14px var(--sans); }
.ap-pop-btn { min-height: 44px; border: 0; border-radius: 14px; background: var(--accent-soft); color: var(--accent-dark); font: 800 15px var(--sans); cursor: pointer; }
.ap-pop p { margin: 0; color: var(--muted); font-size: 12px; }

/* game menu */
.ap-menu { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px; background: rgba(43, 29, 18, 0.35); backdrop-filter: blur(3px); }
.ap-menu[hidden] { display: none; }
.ap-menu-card { width: min(860px, 100%); max-height: 100%; overflow: auto; padding: 18px; border-radius: 28px; background: var(--paper); box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25); animation: ap-rise 0.25s cubic-bezier(.32,.72,0,1) both; }
.ap-menu-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.ap-menu-head h2 { margin: 0; color: var(--ink); font: 900 clamp(22px, 3.4vw, 30px)/1.1 var(--sans); }
.ap-menu-close { width: 46px; height: 46px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 3px 0 #e6dccd; font-size: 20px; cursor: pointer; }
.ap-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.ap-tile { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 132px; padding: 14px 10px 12px; border: 0; border-radius: 22px; background: #fff; box-shadow: 0 5px 0 #e6dccd, 0 10px 20px rgba(70, 40, 15, 0.07); color: var(--ink); font: 800 16px/1.2 var(--sans); text-align: center; cursor: pointer; transition: transform 0.12s ease; }
.ap-tile:active { transform: translateY(3px); box-shadow: 0 2px 0 #e6dccd; }
.ap-tile.current { box-shadow: 0 0 0 4px var(--accent), 0 5px 0 var(--accent-dark); }
.ap-tile.done { background: linear-gradient(180deg, #fff, #f1faf3); }
.ap-tile.soon { opacity: 0.5; cursor: default; }
.ap-tile-icon { display: grid; place-items: center; width: 64px; height: 64px; border-radius: 50%; background: var(--accent-soft); font-size: 34px; color: var(--accent-dark); font-weight: 900; }
.ap-badge { position: absolute; top: 8px; right: 8px; padding: 3px 8px; border-radius: 10px; background: #e3f4e7; color: #2e7d46; font-size: 11.5px; font-weight: 900; }
.ap-badge.soon { background: #eee7dc; color: var(--muted); }

/* layout */
.ap-main { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(150px, 1fr) auto; gap: 12px; padding: 12px; min-height: 0; }
.ap-stage { position: relative; min-height: 0; border-radius: 28px; background: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.04), 0 10px 30px rgba(70, 40, 15, 0.08); overflow: hidden; display: grid; place-items: center; touch-action: manipulation; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
.ap-stage > svg { width: 100%; height: 100%; display: block; }
.ap-panel { min-height: 0; max-height: 52vh; overflow-y: auto; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; padding: 4px; }

/* Ollie the owl speaks */
.ap-say { position: relative; margin: 0; min-height: 0; max-width: 34em; padding: 12px 18px 12px 70px; border-radius: 22px; background: #fff; box-shadow: 0 4px 0 #ece3d6, 0 8px 18px rgba(70, 40, 15, 0.06); color: var(--ink); font: 700 clamp(17px, 2.3vw, 21px)/1.35 var(--sans); text-align: left; }
.ap-say::before { content: "🦉"; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); display: grid; place-items: center; width: 46px; height: 46px; border-radius: 50%; background: var(--accent-soft); font-size: 28px; }
.ap-say:empty { display: none; }
.ap-say small { color: var(--muted); font-size: 0.82em; font-weight: 700; }

/* buttons */
.ap-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.ap-buttons button, .ap-btn { min-width: 60px; min-height: 54px; padding: 0 20px; border: 0; border-radius: 18px; background: #fff; color: var(--ink); box-shadow: 0 4px 0 #e2d6c4, 0 6px 14px rgba(70, 40, 15, 0.06); font: 800 18px/1 var(--sans); cursor: pointer; touch-action: manipulation; transition: transform 0.1s ease; }
.ap-buttons button.primary { background: var(--accent); color: #fff; box-shadow: 0 4px 0 var(--accent-dark), 0 8px 16px rgba(0, 0, 0, 0.1); }
.ap-buttons button:disabled { opacity: 0.4; cursor: default; }
.ap-buttons button:active { transform: translateY(3px); box-shadow: 0 1px 0 #e2d6c4; }
.ap-buttons button.primary:active { box-shadow: 0 1px 0 var(--accent-dark); }
.ap-buttons button[data-pulse] { animation: ap-pulse 1.4s ease-in-out infinite; }
.ap-big { min-height: 84px !important; min-width: 128px !important; font-size: 40px !important; border-radius: 26px !important; }
.ap-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 14px; }
.ap-dots { margin: 0; color: var(--accent); font-size: 18px; letter-spacing: 5px; min-height: 1em; }
.ap-status { margin: 0; padding: 5px 14px; border-radius: 14px; background: var(--accent-soft); color: var(--accent-dark); font: 800 14.5px/1.3 var(--sans); font-variant-numeric: tabular-nums; }
.ap-status:empty { display: none; }
.ap-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.ap-chips button { min-height: 44px; padding: 0 16px; border: 0; border-radius: 22px; background: #fff; box-shadow: 0 3px 0 #e2d6c4; color: var(--ink); font: 800 15px/1 var(--sans); cursor: pointer; }
.ap-chips button[aria-pressed="true"] { background: var(--accent); color: #fff; box-shadow: 0 3px 0 var(--accent-dark); }
.ap-chips button:active { transform: translateY(2px); box-shadow: 0 1px 0 #e2d6c4; }
.ap-cheer { display: inline-block; animation: ap-pop 0.5s cubic-bezier(.32,.72,0,1) both; }
.ap-link { border: 0; background: none; color: var(--accent-dark); font: 800 15px/1 var(--sans); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; padding: 6px; }
.ap-link[hidden] { display: none; }
.ap-buttons button:focus-visible, .ap-icon:focus-visible, .ap-home:focus-visible, .ap-pick:focus-visible, .ap-chips button:focus-visible, .ap-tile:focus-visible { outline: 4px solid #ffcf5c; outline-offset: 3px; }
.nc-cell, .nl-tick, .tf-cell { cursor: pointer; }
@keyframes ap-pop { 0% { transform: scale(0.6); opacity: 0; } 60% { transform: scale(1.15); opacity: 1; } 100% { transform: scale(1); } }
@keyframes ap-pulse { 0%, 100% { box-shadow: 0 4px 0 #e2d6c4; } 50% { box-shadow: 0 4px 0 #e2d6c4, 0 0 0 6px #ffcf5c; } }
@keyframes ap-rise { from { transform: translateY(16px) scale(0.98); opacity: 0; } to { transform: none; opacity: 1; } }

@media (min-width: 760px) { .ap-panel.split { flex-direction: row; gap: 26px; } }
@media (min-aspect-ratio: 17/10) and (max-height: 520px) {
  .ap-main { grid-template-columns: minmax(0, 1.45fr) minmax(260px, 1fr); grid-template-rows: minmax(0, 1fr); }
  .ap-panel { max-height: none; flex-direction: column !important; }
}
@media (max-width: 760px) {
  .ap-bar { flex-wrap: wrap; }
  .ap-title { display: none; }
  .ap-pick { order: 3; flex: 1 1 100%; }
}
@media (max-height: 460px), (max-width: 420px) and (max-height: 720px) {
  .ap-say { font-size: 15.5px; padding: 8px 12px 8px 54px; }
  .ap-say::before { width: 34px; height: 34px; font-size: 20px; left: 10px; }
  .ap-buttons button { min-height: 42px; font-size: 15.5px; padding: 0 14px; }
  .ap-big { min-height: 58px !important; min-width: 96px !important; font-size: 28px !important; }
  .ap-main { padding: 6px; gap: 6px; }
  .ap-panel { gap: 6px; }
  .ap-pick { min-height: 44px; }
  .ap-pick-icon { width: 34px; height: 34px; font-size: 18px; }
  .ap-home, .ap-icon { width: 40px; height: 40px; font-size: 17px; }
  .ap-bar { padding-top: 6px; }
}
@media (prefers-reduced-motion: reduce) { .ap-cheer, .ap-buttons button[data-pulse], .ap-menu-card { animation: none; } }
@media (max-height: 460px) {
  .ap-chips { gap: 5px; }
  .ap-chips button { min-height: 32px; font-size: 13px; padding: 0 10px; }
  .ap-link { padding: 2px; font-size: 13px; }
  .ap-status { padding: 3px 10px; font-size: 13px; }
  .kt-keys button { min-height: 32px !important; font-size: 16px !important; }
  .kt-entry { min-height: 34px !important; line-height: 28px !important; font-size: 22px !important; }
}
/* Phones: home and tools share one row above the game picker, with smaller round buttons. */
@media (max-width: 480px) {
  .ap-bar { gap: 6px; padding: 8px 8px 0; }
  .ap-tools { gap: 5px; }
  .ap-home, .ap-icon { width: 38px; height: 38px; font-size: 16px; box-shadow: 0 2px 0 #e6dccd; }
  .ap-tools .oc-chip { min-height: 38px; padding: 0 8px; font-size: 13.5px; }
  .ap-tools .oc-chip select { max-width: 74px; }
  .ap-pick { min-height: 46px; padding: 3px 12px 3px 4px; }
  .ap-pick-icon { width: 36px; height: 36px; font-size: 19px; }
  .ap-pick-text b { font-size: 16px; }
  .ap-main { padding: 8px; gap: 8px; }
  .ap-stage { border-radius: 22px; }
  .ap-say { font-size: 16px; padding: 9px 12px 9px 56px; }
  .ap-say::before { width: 36px; height: 36px; font-size: 21px; left: 10px; }
}
.ap-turn { position: fixed; left: 50%; bottom: 18px; z-index: 30; transform: translateX(-50%); padding: 10px 16px; border-radius: 22px; background: #2b1d12; color: #fff; font: 800 15px/1.2 var(--sans); white-space: nowrap; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25); pointer-events: none; transition: opacity 0.8s ease; }
.ap-turn.gone { opacity: 0; }
