:root {
  color-scheme: light;
  --paper: #fff9f0;
  --paper-strong: #fffdf8;
  --ink: #253238;
  --muted: #687578;
  --line: #dcd7cc;
  --yellow: #f7c95c;
  --green: #5fd6a1;
  --coral: #ff7f83;
  --blue: #65b8f3;
  --safe-top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
  --safe-right: var(--safe-area-inset-right, env(safe-area-inset-right, 0px));
  --safe-bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  --safe-left: var(--safe-area-inset-left, env(safe-area-inset-left, 0px));
  font-family: ui-rounded, "SF Pro Rounded", "PingFang SC", system-ui, sans-serif;
  font-synthesis: none;
  letter-spacing: 0;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: #cfe3df;
  color: var(--ink);
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
canvas {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  letter-spacing: 0;
}

button:focus-visible,
canvas:focus-visible {
  outline: 4px solid var(--blue);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.game-app {
  display: grid;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  place-items: center;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

.game-shell {
  position: relative;
  display: flex;
  width: min(100%, 1180px);
  height: min(
    calc(100vh - var(--safe-top) - var(--safe-bottom)),
    1180px
  );
  height: min(
    calc(100dvh - var(--safe-top) - var(--safe-bottom)),
    1180px
  );
  min-height: 600px;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(37, 50, 56, 0.18);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 24px 64px rgba(37, 50, 56, 0.17);
  isolation: isolate;
}

.topbar {
  z-index: 2;
  display: flex;
  min-height: 88px;
  flex: 0 0 clamp(88px, 8.5vh, 100px);
  align-items: center;
  gap: 22px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--paper-strong);
}

.brand {
  display: flex;
  min-width: 0;
  flex: 1 1 auto;
  align-items: center;
  gap: 13px;
}

.brand__bee {
  width: 64px;
  height: 64px;
  flex: 0 0 64px;
  object-fit: contain;
  pointer-events: none;
}

.brand__text {
  min-width: 0;
}

.brand__text p,
.brand__text h1,
.status-bar p,
.result-card p,
.result-card h2,
.scoreboard {
  margin: 0;
}

.brand__text p {
  overflow: hidden;
  color: #438976;
  font-size: 11px;
  line-height: 1.1;
  font-weight: 900;
  white-space: nowrap;
}

.brand__text h1 {
  margin-top: 5px;
  font-size: clamp(25px, 3vw, 32px);
  line-height: 1;
  font-weight: 950;
  white-space: nowrap;
}

.scoreboard {
  display: grid;
  min-width: 170px;
  grid-template-columns: repeat(2, minmax(72px, 1fr));
  border-left: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}

.scoreboard > div {
  display: grid;
  min-width: 0;
  justify-items: end;
  padding: 0 14px;
}

.scoreboard > div + div {
  border-left: 1px solid var(--line);
}

.scoreboard dt {
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
  font-weight: 750;
}

.scoreboard dd {
  margin: 5px 0 0;
  font-size: 30px;
  line-height: 1;
  font-weight: 950;
  transform-origin: right center;
}

#scoreValue.is-bouncing {
  animation: score-bounce 320ms ease-out;
}

.controls {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.icon-button {
  display: grid;
  width: 56px;
  height: 56px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(37, 50, 56, 0.11);
}

.icon-button span {
  font-size: 29px;
  line-height: 1;
  font-weight: 850;
}

.icon-button:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: none;
}

.icon-button:disabled {
  cursor: default;
  opacity: 0.34;
  box-shadow: none;
}

.status-bar {
  z-index: 2;
  display: flex;
  min-height: 46px;
  flex: 0 0 46px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 22px;
  border-bottom: 1px solid rgba(220, 215, 204, 0.78);
  background: rgba(255, 253, 248, 0.94);
}

#statusText {
  min-width: 0;
  overflow: hidden;
  font-size: 17px;
  line-height: 1;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.connection-badge {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
  font-weight: 750;
}

.connection-badge span {
  width: 9px;
  height: 9px;
  border: 2px solid #2c8e70;
  border-radius: 50%;
  background: var(--green);
}

.connection-badge[data-state="offline"] span {
  border-color: #c18c20;
  background: var(--yellow);
}

.play-stage {
  position: relative;
  min-height: 0;
  flex: 1 1 auto;
  overflow: hidden;
  background: var(--paper);
  contain: strict;
  touch-action: none;
}

.play-stage,
.play-stage * {
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  -webkit-user-select: none;
  user-select: none;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  background: var(--paper);
  cursor: grab;
  touch-action: none;
}

#gameCanvas:active {
  cursor: grabbing;
}

.toast {
  position: absolute;
  z-index: 4;
  top: 18px;
  left: 50%;
  max-width: calc(100% - 48px);
  padding: 10px 17px;
  border: 2px solid var(--ink);
  border-radius: 7px;
  background: #ffffff;
  color: var(--ink);
  font-size: 17px;
  font-weight: 850;
  white-space: nowrap;
  transform: translateX(-50%);
  box-shadow: 0 5px 0 rgba(37, 50, 56, 0.12);
  animation: toast-in 180ms ease-out;
  pointer-events: none;
}

.result-overlay {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgba(255, 249, 240, 0.94);
  backdrop-filter: blur(6px);
}

.result-card {
  width: min(100%, 420px);
  padding: 30px 30px 28px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: #ffffff;
  text-align: center;
  box-shadow: 10px 10px 0 var(--yellow);
}

.result-card > img {
  width: 94px;
  height: 94px;
  pointer-events: none;
}

.result-kicker {
  margin-top: 7px !important;
  color: #438976;
  font-size: 14px;
  font-weight: 900;
}

.result-card h2 {
  margin-top: 6px;
  font-size: 30px;
  line-height: 1.2;
  font-weight: 950;
}

.result-score {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  margin-top: 15px !important;
  font-variant-numeric: tabular-nums;
}

.result-score strong {
  font-size: 58px;
  line-height: 1;
  font-weight: 950;
}

.result-score span {
  font-size: 19px;
  font-weight: 850;
}

.result-best {
  margin-top: 9px !important;
  color: var(--muted);
  font-size: 16px;
  font-weight: 750;
}

.result-actions {
  display: grid;
  gap: 11px;
  margin-top: 24px;
}

.primary-button,
.secondary-button {
  width: 100%;
  min-height: 56px;
  border-radius: 7px;
  font-size: 19px;
  font-weight: 900;
  cursor: pointer;
}

.primary-button {
  border: 2px solid var(--ink);
  background: var(--green);
  color: var(--ink);
  box-shadow: 0 5px 0 var(--ink);
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
}

.primary-button:active,
.secondary-button:active {
  transform: translateY(2px);
  box-shadow: none;
}

@keyframes score-bounce {
  0% { transform: scale(1); }
  45% { transform: scale(1.25); color: #1e9e74; }
  100% { transform: scale(1); }
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, -8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@media (max-width: 1180px) {
  .game-shell {
    width: 100%;
    height: calc(100vh - var(--safe-top) - var(--safe-bottom));
    height: calc(100dvh - var(--safe-top) - var(--safe-bottom));
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
}

@media (orientation: landscape) and (max-height: 850px) {
  .topbar {
    min-height: 76px;
    flex-basis: 76px;
    gap: 16px;
    padding: 8px 18px;
  }

  .brand__bee {
    width: 54px;
    height: 54px;
    flex-basis: 54px;
  }

  .brand__text h1 {
    font-size: 25px;
  }

  .scoreboard {
    min-width: 158px;
  }

  .scoreboard dd {
    font-size: 26px;
  }

  .icon-button {
    width: 54px;
    height: 54px;
  }

  .status-bar {
    min-height: 42px;
    flex-basis: 42px;
  }
}

@media (max-width: 700px) {
  .topbar {
    gap: 8px;
    padding-right: 10px;
    padding-left: 10px;
  }

  .brand__bee {
    width: 48px;
    height: 48px;
    flex-basis: 48px;
  }

  .brand__text p {
    font-size: 9px;
  }

  .brand__text h1 {
    font-size: 20px;
  }

  .scoreboard {
    min-width: 112px;
    grid-template-columns: repeat(2, minmax(52px, 1fr));
  }

  .scoreboard > div {
    padding: 0 7px;
  }

  .scoreboard dd {
    font-size: 23px;
  }

  .controls {
    gap: 5px;
  }

  .icon-button {
    width: 48px;
    height: 48px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
