:root {
  color-scheme: light;
  --ink: #33405a;
  --ink-soft: #7d7a86;
  --cream: #fbf6ec;
  --navy: #3e5b8b;
  --sky: #6c94c4;
  --olive: #6d7a3d;
  --terra: #d76f4c;
  --mustard: #e8b85d;
  --salmon: #e58b76;
  --paper-img: none;
  --round: 'Fredoka', 'Arial Rounded MT Bold', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: #f2e8d8;
  color: var(--ink);
  font-family: var(--round);
  font-size: 17px;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

#game { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; touch-action: none; display: block; }

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(env(safe-area-inset-top, 0px) + 16px) 16px calc(env(safe-area-inset-bottom, 0px) + 16px);
  background: rgba(242, 232, 216, 0.5);
  overflow-y: auto;
  z-index: 10;
}

.overlay.clear { background: none; pointer-events: none; }
.overlay.clear > * { pointer-events: auto; }

.panel {
  position: relative;
  width: 100%;
  max-width: 380px;
  --fill: #f1e7d6;
  padding: 22px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-weight: 500;
}

#menu { align-items: flex-end; padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 24px); background: none; }
#menu .panel { max-width: 360px; }
#logo { display: block; width: min(100%, 320px); height: auto; margin: -6px auto 2px; }

h2 { margin: 0; font-weight: 700; font-size: 28px; line-height: 1.05; color: var(--navy); }
p { margin: 0; line-height: 1.38; font-size: 16px; }
.note { color: var(--ink-soft); font-size: 14px; }
ul.rules { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; line-height: 1.35; font-size: 16px; }
ul.rules b { color: var(--navy); }

button {
  font-family: var(--round);
  font-weight: 700;
  font-size: 18px;
  color: var(--cream);
  --fill: var(--sky);
  border: none;
  padding: 10px 14px;
  cursor: pointer;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
}

button:nth-child(2n) { transform: rotate(0.9deg); }
button:nth-child(2n+1) { transform: rotate(-0.8deg); }
button:active { translate: 0 2px; }
button:focus-visible { outline: 3px dashed var(--terra); outline-offset: 3px; }

.primary { font-size: 24px; --fill: var(--terra); min-height: 58px; }
.navy { --fill: var(--navy); }
.olive { --fill: var(--olive); }
.light { --fill: #fbf6ec; color: var(--ink); }
.mustard { --fill: var(--mustard); color: var(--ink); }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.icon-btn {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  right: calc(env(safe-area-inset-right, 0px) + 12px);
  width: 46px;
  height: 46px;
  min-height: 0;
  padding: 0;
  --fill: var(--navy);
  font-size: 16px;
  transform: rotate(4deg);
  z-index: 5;
}

:is(button, .panel, .chip) {
  isolation: isolate;
  background: none;
  border-radius: 0;
  box-shadow: none;
  filter: drop-shadow(0 3px 2.5px rgba(80, 60, 40, 0.26));
}
:is(button:not(.icon-btn), .panel, .chip) { position: relative; }
:is(button, .panel, .chip)::before,
:is(button, .panel, .chip)::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: var(--paper-img);
  background-blend-mode: multiply;
}
:is(button, .panel, .chip)::before {
  z-index: -2;
  background-color: var(--bc, #f4ecdc);
  clip-path: var(--back, none);
  transform: translate(var(--bx, 3px), var(--by, 4px)) rotate(var(--br, 0.8deg));
}
:is(button, .panel, .chip)::after {
  z-index: -1;
  background-color: var(--fill, var(--sky));
  clip-path: var(--cut, none);
}

.code-box { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.code { font-size: 44px; font-weight: 700; letter-spacing: 0.12em; color: var(--navy); font-variant-numeric: tabular-nums; }
.join-row { grid-template-columns: 1.4fr 1fr; align-items: center; }
#codeIn { font-family: var(--round); font-weight: 600; font-size: 22px; letter-spacing: 0.1em; text-align: center; min-height: 48px; border: 2px dashed #b9ab95; background: #fbf6ec; color: var(--ink); border-radius: 6px; padding: 6px; width: 100%; }
.net-status { min-height: 1.3em; text-align: center; font-weight: 600; color: var(--ink-soft); font-size: 15px; margin: 0; }
.net-status.bad { color: var(--terra); }

#end { background: none; align-items: flex-end; padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 20px); }
#end .panel { max-width: 340px; align-items: stretch; text-align: center; }
#endWord { display: block; margin: 0 auto; max-width: 100%; height: auto; }

#zoo { position: fixed; inset: 0; z-index: 20; display: grid; grid-template-rows: auto 1fr auto; background: #f2e8d8; }
#zoo header { display: flex; align-items: center; justify-content: space-between; padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 6px; gap: 10px; }
#zoo header h2 { font-size: 26px; }
#zooView { position: relative; min-height: 0; }
#zooCanvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
#zoo .bar { display: flex; flex-direction: column; gap: 8px; padding: 6px 12px calc(env(safe-area-inset-bottom, 0px) + 12px); }
#zoo .chips { display: flex; flex-wrap: wrap; gap: 7px; justify-content: center; }
#zoo .chips button { min-height: 36px; font-size: 14px; padding: 4px 11px; --fill: #fbf6ec; color: var(--ink); }
#zoo .chips button.on { --fill: var(--mustard); }
#zoo .chips.anims button { --fill: var(--sky); color: var(--cream); }
#zoo .chips.anims button.on { --fill: var(--terra); }
#zoo .label { text-align: center; font-weight: 600; color: var(--ink-soft); font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; }

@media (orientation: landscape) {
  #menu { align-items: center; justify-content: flex-end; padding-right: max(24px, 7vw); }
}

@media (orientation: landscape) and (max-height: 560px) {
  #menu { align-items: center; justify-content: flex-end; padding-right: 24px; }
  .panel { padding: 14px 16px 14px; gap: 9px; }
  #logo { width: 240px; }
  button { min-height: 42px; }
  .primary { min-height: 48px; font-size: 20px; }
}
