* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: #dac6a5; color: #fff; font-family: system-ui, sans-serif; overflow-x: clip; isolation: isolate; }
body::before { content: ""; position: fixed; inset: 0; z-index: -2; background: url("assets/kitchen-cartoon.png") center center / cover no-repeat; pointer-events: none; }
.game-select { flex-wrap: wrap; background: #fff8eee8; border-bottom-color: #cfb58e; backdrop-filter: blur(12px); }
.game-select a { padding: 8px 14px; color: #74563e; }
.game-select a:hover { background: #efdfc7; }
.game-select a[aria-current=page] { background: #8b6247; border-color: #754d34; box-shadow: 0 3px 0 #5a3c2a; }
.container { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; min-height: calc(100svh - var(--header-height, 64px)); gap: 24px; padding: 32px 24px 20px; }
.game-layout { display: flex; align-items: flex-end; justify-content: center; gap: clamp(20px, 3vw, 40px); width: 100%; }
.game-column { display: flex; flex-direction: column; align-items: center; flex-shrink: 0; }
.start-actions { display: flex; justify-content: center; align-items: flex-end; height: 64px; }
#openStartButton { min-width: 160px; min-height: 44px; padding: 11px 30px; border: 1px solid #6e4e32; border-radius: 9px; background: #8b6247; color: #fffaf0; box-shadow: 0 3px 0 #5d3e2a; font: 700 16px system-ui, sans-serif; cursor: pointer; }
#openStartButton:hover { background: #765139; }
.scene { display: flex; align-items: flex-end; gap: 24px; width: 100%; max-width: 1130px; }
.scene .game-layout { flex: 1; min-width: 0; }
.ranking-panel { position: relative; isolation: isolate; align-self: flex-start; display: flex; flex-direction: column; flex: 0 0 250px; max-height: min(680px, calc(100svh - 185px)); padding: 22px 14px 30px; color: #5f4d37; filter: drop-shadow(2px 5px 2px #49392338); }
.ranking-heading { padding-bottom: 8px; border-bottom: 2px solid #9b8a6959; border-radius: 0 0 45% 12%; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.ranking-heading h2 { margin: 0; font-size: 16px; color: #635b49; }
.ranking-panel button { padding: 6px 10px; border: 1px solid #b8a481; border-radius: 6px; background: #eee5d2; color: #634a31; font: inherit; cursor: pointer; }
.ranking-panel button:disabled { opacity: .5; cursor: default; }
#refreshBtn { font-size: 22px; }
.ranking-panel p { font-size: 12px; line-height: 1.6; }
#saveStatus { color: #71552b; }
#retryBtn { margin-top: 8px; font-size: 12px; }
.rank-caption { padding-top: 13px; border-top: 1px solid #d9cfba; }
#rankStatus { margin-bottom: 8px; }
#rankingList { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior-y: contain; scrollbar-width: thin; margin: 0; padding: 0; list-style: none; }
#rankingList li { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; gap: 6px; align-items: center; padding: 10px 0; border-bottom: 1px solid #e3dac7; font-size: 13px; }
#rankingList li > span { color: #9a753b; font-weight: 700; }
#rankingList b { overflow-wrap: anywhere; }
#rankingList small { display: block; margin-top: 3px; font-size: 10px; color: #8a795f; }
#rankingList strong { font-size: 14px; color: #785627; }
.rank-foot { flex-shrink: 0; border-top: 1px solid #d9cfba; padding-top: 10px; }
[hidden] { display: none !important; }
@media (max-width: 760px) {
  .scene { flex-direction: column; align-items: center; }
  .scene .game-layout { flex: none; }
  .ranking-panel { order: -1; align-self: flex-end; flex: none; width: min(280px, 100%); max-height: 320px; }
}
.planet-catalog {
  margin-bottom: 64px;
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  flex: 0 0 clamp(80px, 22vw, 180px);
  max-height: var(--game-height, 770px);
  padding: 22px 10px 30px;
  filter: drop-shadow(2px 5px 2px #49392338);
}
/* Opaque, faded paper with a faint adhesive band and tiny paper fibers. */
.planet-catalog::before, .ranking-panel::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0;
  border: 1.5px solid #9d9279;
  border-radius: 3px 2px 0 4px / 2px 5px 0 3px;
  background:
    linear-gradient(180deg, #c9bea329 0 16px, transparent 16px),
    radial-gradient(ellipse at 18% 30%, #a2937612 0 0.7px, transparent 1px) 0 0 / 7px 9px,
    radial-gradient(ellipse at 72% 70%, #fffef970 0 0.8px, transparent 1.2px) 0 0 / 11px 13px,
    linear-gradient(115deg, #faf8ee, #f1eddd 75%, #e8e2cf);
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - 26px), calc(100% - 26px) 100%, 0 100%);
  pointer-events: none;
}
/* The lifted corner shows the slightly darker underside of the paper. */
.planet-catalog::after, .ranking-panel::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  width: 26px;
  height: 26px;
  border: 1px solid #9d9279;
  border-radius: 5px 0 0 0 / 12px 0 0 0;
  background: linear-gradient(135deg, #bfb69e, #e7e0cc 38%, #fffdf3 72%, #d6ccb4);
  clip-path: polygon(0 0, 100% 0, 0 100%);
  filter: drop-shadow(-2px -2px 1px #75644730);
  pointer-events: none;
}
.planet-catalog h2 { flex-shrink: 0; margin: 0 0 10px; padding-bottom: 8px; border-bottom: 2px solid #9b8a6959; border-radius: 0 0 45% 12%; text-align: center; font-size: 15px; color: #635b49; }
.planet-catalog ol { display: grid; gap: 4px; min-height: 0; overflow-y: auto; overscroll-behavior-y: contain; scrollbar-width: thin; scrollbar-color: #b4aa91 #ede9db; margin: 0; padding: 0; list-style: none; }
.planet-catalog ol:focus-visible { outline: 2px solid #a6b9d9; outline-offset: 2px; }
.planet-entry { display: flex; align-items: center; gap: 8px; min-height: 36px; padding: 4px; border-radius: 8px; color: #77634e; font-size: 13px; }
.planet-entry.is-unlocked { background: #d9c98538; color: #514a39; border-radius: 3px 7px 4px 6px; }
.planet-entry img { width: 28px; height: 28px; object-fit: contain; flex: 0 0 28px; }
.planet-entry .planet-mystery { width: 28px; height: 28px; flex: 0 0 28px; border: 1px dashed #a58f74; border-radius: 50%; }
.planet-entry .planet-name { overflow-wrap: anywhere; }
.catalog-reveal { position: fixed; z-index: 100; top: 0; left: 0; object-fit: contain; transform-origin: 0 0; pointer-events: none; user-select: none; opacity: 0; filter: drop-shadow(0 5px 12px #35291c55); will-change: transform, opacity; }
@media (max-width: 600px) {
  .planet-catalog { padding: 20px 5px 30px; }
  .planet-catalog h2 { font-size: 12px; }
  .planet-entry { gap: 4px; padding: 3px 1px; font-size: 11px; }
  .planet-entry img, .planet-entry .planet-mystery { width: 22px; height: 22px; flex-basis: 22px; }
}
#game { position: relative; isolation: isolate; flex-shrink: 0; width: 480px; line-height: 0; user-select: none; }
/* A single vector contour joins the lip, sides and base without overlapping rings. */
.glass-shell {
  position: absolute; z-index: 3; top: calc(var(--cup-top) - 28px); left: -12px;
  width: 504px; height: calc(100% - var(--cup-top) + 28px);
  pointer-events: none; user-select: none;
}
.water-surface {
  position: absolute; z-index: 0;
  top: calc(var(--cup-top) + 38px); left: 0; width: 480px; height: 64px;
  border: 2px solid #badde887; border-bottom: 3px solid #a7e6f8aa;
  border-radius: 50%;
  background: radial-gradient(ellipse at 28% 32%, #defbff47, transparent 47%), linear-gradient(180deg, #86ced944, #42768d38 55%, #79bed54d);
  box-shadow: inset 0 5px 8px #07203645, inset 0 -3px 4px #cbf7ff33, 0 7px 15px #6bbcd61c;
  pointer-events: none;
}
.water-surface::before, .water-surface::after {
  content: ""; position: absolute; inset: 9px 31px;
  border: 1px solid #d9faff45; border-left-color: transparent; border-right-color: transparent;
  border-radius: 50%; animation: water-shimmer 7s ease-in-out infinite alternate;
}
.water-surface::after { inset: 18px 89px; animation-delay: -3.5s; opacity: 0.5; }
@keyframes water-shimmer { from { transform: scaleX(0.92); opacity: 0.3; } to { transform: scaleX(1.04); opacity: 0.75; } }
@media (prefers-reduced-motion: reduce) { .water-surface::before, .water-surface::after { animation: none; } }
.cup-shadow { position: absolute; z-index: -1; bottom: -25px; left: -50px; width: 610px; height: 58px; border-radius: 50%; background: radial-gradient(ellipse, #21150875, #39251838 48%, transparent 72%); filter: blur(9px); transform: rotate(-3deg); pointer-events: none; }
#canvas { position: relative; display: block; border-radius: 24px 24px 0 0 / 17px 17px 0 0; touch-action: none; }
#floor {
  position: relative; width: 480px; height: 50px;
  border-radius: 0 0 50% 50% / 0 0 26px 26px;
  background: linear-gradient(180deg, #080e24, #234155 26%, #799daa9c 64%, #c1dcd49c);
}
#overlay { position: absolute; inset: 0 0 auto; height: 720px; display: flex; align-items: center; justify-content: center; z-index: 2; }
#playAgainButton { margin-top: 160px; padding: 12px 24px; border: 0; border-radius: 10px; color: #fff; background: #288b40; font: 700 22px system-ui, sans-serif; cursor: pointer; }
button:focus-visible { outline: 3px solid #fbd76c; outline-offset: 4px; }
#footer { text-align: center; padding: 10px 20px; max-width: 100%; border: 1px solid #fff9e1b3; border-radius: 16px; color: #4e351f; background: #fff8e9de; box-shadow: 0 4px 18px #52371d1f; backdrop-filter: blur(8px); }
h1 { margin: 0; font-size: 20px; }
h1 small { margin-left: 8px; font-size: 11px; color: #8a6846; }
p { margin: 8px 0 0; font-size: 13px; line-height: 1.5; color: #725438; }

#startDialog { width: min(380px, calc(100% - 32px)); padding: 28px; border: 1px solid #bbae93; border-radius: 12px; background: #faf7ed; color: #594630; box-shadow: 0 18px 60px #2d241b45; }
#startDialog::backdrop { background: #211c174d; backdrop-filter: blur(3px); }
#startDialog h2 { margin: 0; padding-right: 30px; font-size: 24px; }
#closeStartButton { position: absolute; top: 8px; right: 8px; display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 6px; background: transparent; color: #73583d; font: 28px/1 system-ui, sans-serif; cursor: pointer; }
#closeStartButton:hover { background: #e9e1d1; }
#nicknameHelp { font-size: 12px; }
#startError { min-height: 20px; color: #a1422e; font-size: 13px; }
#startButton { width: 100%; margin-top: 12px; padding: 13px; border: 1px solid #6e4e32; border-radius: 7px; background: #8b6247; color: #fffaf0; font: 700 16px system-ui, sans-serif; cursor: pointer; }

#playerName { margin: 22px 0 12px; font-size: 20px; font-weight: 700; }
#accountLink { color: #765135; text-underline-offset: 3px; }
#startButton:disabled { opacity: .6; cursor: wait; }
@media (max-width: 600px) { .cup-shadow { width: 560px; } }
