:root {
  --ink: #2b1b0e;
  --paper: #fff6e0;
  --paper-2: #ffe7b0;
  --orange: #ff8c1a;
  --good: #3fa34d;
  --bad: #d7263d;
  --px: 4px;
}

* { box-sizing: border-box; }

html { background: #6ec6ff; }

body {
  margin: 0;
  min-height: 100%;
  background: transparent;
  color: var(--ink);
  font-family: 'VT323', monospace;
  font-size: 22px;
}

#bg {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  image-rendering: pixelated;
  z-index: -1;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

h2 {
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  margin: 0 0 14px;
  letter-spacing: 1px;
}

/* Pixel border helper: stepped corners via box-shadow */
.panel, .bubble, .btn, textarea, dialog {
  border: none;
  box-shadow:
    0 calc(var(--px) * -1) 0 0 var(--ink),
    0 var(--px) 0 0 var(--ink),
    calc(var(--px) * -1) 0 0 0 var(--ink),
    var(--px) 0 0 0 var(--ink);
}

/* ---------- Stage ---------- */
.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 62vh;
  justify-content: flex-end;
  padding-bottom: 12px;
}

.bubble {
  position: relative;
  background: var(--paper);
  padding: 16px 24px 14px;
  text-align: center;
  max-width: 100%;
  margin-bottom: 26px;
}
.bubble::after {
  /* stepped pixel tail */
  content: '';
  position: absolute;
  left: 50%;
  bottom: -4px;
  width: 4px;
  height: 4px;
  background: transparent;
  box-shadow:
    -8px 4px 0 var(--ink), -4px 4px 0 var(--paper), 0 4px 0 var(--paper), 4px 4px 0 var(--paper), 8px 4px 0 var(--ink),
    -4px 8px 0 var(--ink), 0 8px 0 var(--paper), 4px 8px 0 var(--ink),
    0 12px 0 var(--ink);
}
.bubble-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  opacity: .7;
}
.bubble-name {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(18px, 5vw, 34px);
  margin: 10px 0 8px;
  color: #c24e00;
  word-break: break-word;
}
.bubble-quote { font-size: 24px; min-height: 1em; }

.orange-wrap {
  position: relative;
  width: 240px;
  height: 240px;
  animation: bob 1.6s steps(4) infinite;
}
#orange {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}
.orange-wrap.shake { animation: shake .08s steps(2) 8; }
.orange-wrap.jump { animation: jump .5s steps(5); }
.orange-wrap.furious { animation: rage .15s steps(2) infinite; }

@keyframes bob { 50% { transform: translateY(-8px); } }
@keyframes shake { 0% { transform: translateX(-10px); } 100% { transform: translateX(10px); } }
@keyframes jump { 40% { transform: translateY(-50px); } }
@keyframes rage { 0% { transform: translate(-3px, 0); } 100% { transform: translate(3px, -2px); } }

.steam { position: absolute; inset: 0; display: none; pointer-events: none; }
.orange-wrap.furious .steam { display: block; }
.steam i {
  position: absolute;
  top: 10px;
  width: 20px;
  height: 20px;
  background: #fff;
  opacity: .9;
  animation: puff 1s steps(5) infinite;
}
.steam i:nth-child(1) { left: 20px; }
.steam i:nth-child(2) { right: 20px; animation-delay: .33s; }
.steam i:nth-child(3) { left: 110px; top: -10px; animation-delay: .66s; }
@keyframes puff {
  0% { transform: translateY(0) scale(.6); opacity: .9; }
  100% { transform: translateY(-60px) scale(1.4); opacity: 0; }
}

.stamp {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-12deg) scale(0);
  font-family: 'Press Start 2P', monospace;
  font-size: 30px;
  color: #fff;
  background: var(--bad);
  padding: 10px 14px;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 0 0 4px var(--ink);
}
.stamp.good { background: var(--good); }
.stamp.show { animation: stamp 1.3s steps(6) forwards; }
@keyframes stamp {
  0% { transform: translate(-50%, -50%) rotate(-12deg) scale(3); opacity: 0; }
  20% { transform: translate(-50%, -50%) rotate(-12deg) scale(1); opacity: 1; }
  80% { opacity: 1; }
  100% { transform: translate(-50%, -50%) rotate(-12deg) scale(1); opacity: 0; }
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: center;
  margin-top: 24px;
}

.btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  padding: 14px 16px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  position: relative;
  top: 0;
  border-bottom: 6px solid rgba(0,0,0,.25);
}
.btn:hover { filter: brightness(1.08); }
.btn:active { top: 4px; border-bottom-width: 2px; }
.btn.good { background: var(--good); color: #fff; }
.btn.bad { background: var(--bad); color: #fff; }
.btn.small { font-size: 10px; padding: 10px 12px; }

/* ---------- Panels ---------- */
.panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 24px;
  margin-top: 36px;
}
.panel {
  background: var(--paper);
  padding: 18px;
}

.ranking { list-style: none; margin: 0; padding: 0; }
.ranking li {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 6px;
  cursor: pointer;
}
.ranking li:hover { background: var(--paper-2); }
.ranking li.current { background: #ffd08a; }
.ranking canvas { width: 36px; height: 36px; image-rendering: pixelated; }
.ranking .name { font-size: 24px; line-height: 1; overflow: hidden; text-overflow: ellipsis; }
.ranking .name small { display: block; font-size: 17px; opacity: .65; }
.ranking .marks { display: flex; gap: 3px; flex-wrap: wrap; justify-content: flex-end; max-width: 120px; }
.ranking .marks b { width: 10px; height: 10px; background: var(--bad); box-shadow: inset -2px -2px 0 rgba(0,0,0,.3); }
.ranking .marks span { font-family: 'Press Start 2P', monospace; font-size: 10px; }
.ranking .crown { font-size: 16px; }

textarea {
  width: 100%;
  font-family: 'VT323', monospace;
  font-size: 22px;
  padding: 8px;
  background: #fff;
  color: var(--ink);
  resize: vertical;
  margin: 4px 0 18px;
}
.row { display: flex; gap: 14px; flex-wrap: wrap; }

.history { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow: auto; }
.history li { padding: 3px 0; border-bottom: 2px dashed var(--paper-2); }
.history .when { opacity: .55; font-size: 18px; }
.hint { font-size: 18px; opacity: .6; margin: 10px 0 0; }
.empty { opacity: .6; }

/* ---------- Share ---------- */
.share-icon svg, .share-mini svg { display: block; width: 18px; height: 18px; fill: currentColor; }
.share-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: 6px;
  background: transparent;
  border: none;
  color: var(--ink);
  cursor: pointer;
  opacity: .55;
}
.share-btn:hover { opacity: 1; background: var(--paper-2); }
.bubble { padding-left: 44px; padding-right: 44px; }
.btn.icon { padding: 11px 13px; }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.share-mini {
  float: right;
  margin-top: 4px;
  padding: 3px;
  background: transparent;
  border: none;
  color: var(--bad);
  cursor: pointer;
}
.share-mini svg { width: 14px; height: 14px; }
.share-mini:hover { background: var(--paper-2); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 120px);
  background: var(--paper);
  font-family: 'Press Start 2P', monospace;
  font-size: 11px;
  padding: 14px 18px;
  box-shadow: 0 0 0 4px var(--ink);
  transition: transform .2s steps(4);
  z-index: 10;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show { transform: translate(-50%, 0); }

/* ---------- Generic ---------- */
[hidden] { display: none !important; }
a { color: #c24e00; }

input[type="text"], input[type="password"], input:not([type]) {
  width: 100%;
  font-family: 'VT323', monospace;
  font-size: 22px;
  padding: 8px;
  background: #fff;
  color: var(--ink);
  margin: 4px 0 12px;
  box-shadow: 0 0 0 var(--px) var(--ink);
}
input:focus, textarea:focus { outline: 3px dashed var(--orange); outline-offset: 4px; }
.btn:focus-visible { outline: 3px dashed var(--ink); outline-offset: 6px; }
.btn.big { font-size: 14px; padding: 18px 22px; }
.form-error { color: var(--bad); min-height: 1em; margin: 0 0 10px; }

/* ---------- Home ---------- */
.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding-top: 24px;
}
.logo {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(24px, 7vw, 64px);
  margin: 0 0 18px;
  color: var(--orange);
  text-shadow: 4px 4px 0 var(--ink), -2px -2px 0 var(--ink), 2px -2px 0 var(--ink), -2px 2px 0 var(--ink);
  letter-spacing: 2px;
}
.logo span { display: inline-block; animation: wave 1.8s steps(3) infinite; }
.logo span:nth-child(odd) { color: #ffc266; }
.logo span:nth-child(1) { animation-delay: 0s; }
.logo span:nth-child(2) { animation-delay: .1s; }
.logo span:nth-child(3) { animation-delay: .2s; }
.logo span:nth-child(4) { animation-delay: .3s; }
.logo span:nth-child(5) { animation-delay: .4s; }
.logo span:nth-child(6) { animation-delay: .5s; }
.logo span:nth-child(7) { animation-delay: .6s; }
.logo span:nth-child(8) { animation-delay: .7s; }
.logo span:nth-child(9) { animation-delay: .8s; }
.logo span:nth-child(10) { animation-delay: .9s; }
.logo span:nth-child(11) { animation-delay: 1s; }
@keyframes wave { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-10px); } }

.tagline {
  background: var(--paper);
  padding: 10px 16px;
  font-size: 24px;
  max-width: 640px;
  margin: 0 0 30px;
  box-shadow: 0 0 0 var(--px) var(--ink);
}
.small-bubble { margin-bottom: 20px; min-width: min(420px, 90vw); padding: 12px 20px; }
.home-orange {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  width: 200px;
  height: 200px;
}
.home-orange canvas { width: 100%; height: 100%; image-rendering: pixelated; }
.home-orange:focus-visible { outline: 3px dashed var(--ink); }

.cta { display: flex; flex-wrap: wrap; gap: 20px; justify-content: center; margin: 30px 0 10px; }

.steps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 24px;
  margin-top: 40px;
}
.step { position: relative; padding-top: 26px; }
.step p { margin: 0; }
.step-n {
  position: absolute;
  top: -18px;
  left: 14px;
  font-family: 'Press Start 2P', monospace;
  font-size: 14px;
  background: var(--orange);
  color: #fff;
  padding: 8px 10px;
  box-shadow: 0 0 0 var(--px) var(--ink);
}
.mood-strip { display: flex; gap: 8px; margin-top: 10px; }
.mood-strip figure { margin: 0; text-align: center; }
.mood-strip canvas { width: 44px; height: 44px; image-rendering: pixelated; }
.mood-strip figcaption { font-size: 15px; opacity: .7; }

.form-panel { max-width: 620px; margin: 36px auto 0; }
.form-panel label { display: block; }
.form-panel small { opacity: .6; }
fieldset { border: 2px dashed var(--paper-2); margin: 0 0 14px; padding: 8px 12px 0; }
legend { font-family: 'Press Start 2P', monospace; font-size: 10px; padding: 0 6px; }
.choice { display: flex !important; align-items: center; gap: 8px; margin-bottom: 8px; cursor: pointer; }
.choice input { width: 18px; height: 18px; accent-color: var(--orange); margin: 0; }
.code-input { text-transform: uppercase; letter-spacing: 6px; font-size: 30px !important; text-align: center; }

/* ---------- Room ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 10px 14px;
}
.home-link { font-size: 30px; text-decoration: none; }
.room-title { flex: 1; min-width: 160px; }
.room-name { font-family: 'Press Start 2P', monospace; font-size: 13px; margin-bottom: 4px; word-break: break-word; }
.code-chip {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  letter-spacing: 2px;
  background: var(--paper-2);
  border: none;
  padding: 4px 8px;
  cursor: pointer;
  color: var(--ink);
}
.code-chip:hover { background: #ffd08a; }
.badge { font-size: 17px; opacity: .7; margin-left: 6px; }
.btn.lock { background: #ffd08a; }
.ranking li.readonly { cursor: default; }
.ranking li.readonly:hover { background: transparent; }
.ranking li.readonly.current { background: #ffd08a; }

/* ---------- Dialogs ---------- */
dialog {
  max-width: min(560px, calc(100vw - 32px));
  width: 100%;
  color: var(--ink);
  font-family: 'VT323', monospace;
  font-size: 22px;
}
dialog::backdrop { background: rgba(43, 27, 14, .55); }
dialog h2 { font-size: 13px; line-height: 1.5; }
.warn { background: #ffe0e0; padding: 8px 10px; margin: 0 0 14px; }
.secrets { margin: 0 0 16px; }
.secrets dt { font-size: 17px; opacity: .65; margin-top: 8px; }
.secrets dd { margin: 0; display: flex; gap: 8px; align-items: center; }
.secrets code {
  flex: 1;
  background: #fff;
  padding: 4px 8px;
  font-family: 'VT323', monospace;
  font-size: 20px;
  word-break: break-all;
  box-shadow: 0 0 0 2px var(--ink);
}
.copy-mini { background: none; border: none; cursor: pointer; font-size: 18px; padding: 4px; }
.copy-mini:hover { background: var(--paper-2); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
.topbar { margin-bottom: 36px; }
