:root {
  color-scheme: light;
  --ink: #1e2a24;
  --panel: rgba(255, 250, 231, 0.92);
  --panel-strong: #fff7d6;
  --accent: #d9512c;
  --accent-dark: #9c321d;
  --green: #276c42;
  --line: rgba(62, 50, 33, 0.2);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  overflow: hidden;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  background: #203b32;
  color: var(--ink);
  font-family: "Segoe UI", system-ui, sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

button {
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
}

.game-shell {
  width: min(1120px, 100%);
  max-height: calc(100dvh - 20px);
}

.scorebar,
.controls {
  display: grid;
  gap: 10px;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.22);
}

.scorebar {
  grid-template-columns: 1.4fr repeat(3, 0.65fr);
  border-radius: 8px 8px 0 0;
}

.scorebar > div {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.label {
  color: #725c33;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.scorebar strong {
  overflow: hidden;
  font-size: clamp(1rem, 2vw, 1.35rem);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.field-wrap {
  position: relative;
  overflow: hidden;
  background: #67895f;
  border-inline: 1px solid var(--line);
}

canvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #91b46f;
  touch-action: none;
  user-select: none;
}

.message {
  position: absolute;
  inset: 0;
  display: none;
  place-content: center;
  justify-items: center;
  gap: 12px;
  padding: 24px;
  background: rgba(33, 43, 35, 0.5);
  color: #fff9df;
  text-align: center;
}

.message.is-visible {
  display: grid;
}

.message h1 {
  margin: 0;
  font-size: clamp(2rem, 7vw, 5rem);
  line-height: 0.96;
  text-shadow: 0 4px 18px rgba(0, 0, 0, 0.38);
}

.message p {
  max-width: 28rem;
  margin: 0;
  font-weight: 700;
}

.message button {
  min-width: 132px;
  min-height: 44px;
  padding: 0 20px;
  background: var(--accent);
  color: white;
  font-weight: 800;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.2);
}

.mobile-controls {
  display: none;
}

.mobile-controls,
.joystick,
.joystick-knob,
.swing-button,
canvas {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.rotate-notice {
  display: none;
}

.controls {
  grid-template-columns: repeat(3, 1fr);
  border-radius: 0 0 8px 8px;
}

.meter {
  display: grid;
  grid-template-columns: minmax(52px, 0.65fr) 1fr minmax(62px, auto);
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-weight: 800;
}

progress {
  width: 100%;
  height: 14px;
  accent-color: var(--green);
}

.upgrade {
  min-height: 34px;
  padding: 0 10px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  color: var(--accent-dark);
  font-weight: 900;
}

.upgrade:disabled {
  cursor: default;
  opacity: 0.42;
}

.reset-progress {
  min-height: 34px;
  padding: 0 12px;
  background: #2d3f38;
  color: #fff7d6;
  font-weight: 900;
}

@media (max-width: 720px) {
  body {
    align-items: start;
    padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  }

  .game-shell {
    display: grid;
    grid-template-rows: auto auto auto;
    width: 100%;
    max-height: none;
  }

  .scorebar,
  .controls {
    gap: 6px;
    padding: 7px;
  }

  .scorebar {
    grid-template-columns: repeat(2, 1fr);
  }

  .label {
    font-size: 0.64rem;
  }

  .scorebar strong {
    font-size: 0.98rem;
  }

  .field-wrap {
    border-inline: 0;
  }

  .mobile-controls {
    position: absolute;
    inset: auto 12px 12px 12px;
    z-index: 3;
    display: flex;
    align-items: end;
    justify-content: space-between;
    pointer-events: none;
  }

  .joystick,
  .swing-button {
    pointer-events: auto;
    touch-action: none;
    user-select: none;
  }

  .joystick {
    position: relative;
    width: 86px;
    height: 86px;
    border: 2px solid rgba(255, 247, 214, 0.8);
    border-radius: 50%;
    background: rgba(30, 42, 36, 0.36);
    box-shadow: inset 0 0 18px rgba(255, 247, 214, 0.18), 0 8px 18px rgba(0, 0, 0, 0.22);
  }

  .joystick-knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #fff7d6;
    border: 2px solid rgba(62, 50, 33, 0.32);
    transform: translate(-50%, -50%);
    box-shadow: 0 5px 12px rgba(0, 0, 0, 0.24);
  }

  .swing-button {
    width: 84px;
    height: 84px;
    border-radius: 50%;
    background: #d9512c;
    color: #fff7d6;
    font-size: 1.1rem;
    font-weight: 950;
    text-transform: uppercase;
    box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.2), 0 8px 18px rgba(0, 0, 0, 0.24);
  }

  canvas {
    height: auto;
    max-height: min(56dvh, 62vw);
    object-fit: contain;
  }

  .message {
    gap: 8px;
    padding: 16px;
  }

  .message h1 {
    font-size: clamp(1.8rem, 11vw, 3.2rem);
  }

  .message p {
    font-size: 0.9rem;
  }

  .controls {
    grid-template-columns: 1fr;
  }

  .meter {
    grid-template-columns: 54px 1fr 58px;
    gap: 6px;
    font-size: 0.88rem;
  }

  progress {
    height: 12px;
  }

  .upgrade {
    min-height: 30px;
    padding: 0 8px;
  }

  .reset-progress {
    min-height: 34px;
  }
}

@media (max-width: 720px) and (orientation: portrait) {
  .game-shell {
    visibility: hidden;
  }

  .rotate-notice {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: grid;
    place-content: center;
    gap: 10px;
    padding: 24px;
    background: #203b32;
    color: #fff7d6;
    text-align: center;
  }

  .rotate-notice strong {
    font-size: 1.8rem;
  }

  .rotate-notice span {
    font-weight: 800;
  }
}

@media (max-width: 720px) and (orientation: landscape), (max-height: 520px) and (orientation: landscape) {
  body {
    place-items: center;
    padding: max(4px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }

  .game-shell {
    visibility: visible;
    display: grid;
    width: min(100%, 960px);
    height: calc(100dvh - 8px);
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .field-wrap {
    min-height: 0;
    border-inline: 0;
  }

  .mobile-controls {
    position: absolute;
    inset: auto 16px 14px 16px;
    z-index: 3;
    display: flex;
    align-items: end;
    justify-content: space-between;
    pointer-events: none;
  }

  .joystick,
  .swing-button {
    width: 76px;
    height: 76px;
    pointer-events: auto;
    touch-action: none;
    user-select: none;
  }

  .joystick {
    position: relative;
    border: 2px solid rgba(255, 247, 214, 0.8);
    border-radius: 50%;
    background: rgba(30, 42, 36, 0.36);
    box-shadow: inset 0 0 18px rgba(255, 247, 214, 0.18), 0 8px 18px rgba(0, 0, 0, 0.22);
  }

  .joystick-knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #fff7d6;
    border: 2px solid rgba(62, 50, 33, 0.32);
    transform: translate(-50%, -50%);
    box-shadow: 0 5px 12px rgba(0, 0, 0, 0.24);
  }

  .swing-button {
    border-radius: 50%;
    background: #d9512c;
    color: #fff7d6;
    font-size: 1rem;
    font-weight: 950;
    text-transform: uppercase;
    box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.2), 0 8px 18px rgba(0, 0, 0, 0.24);
  }

  .scorebar {
    grid-template-columns: 1.4fr repeat(3, 0.65fr);
  }

  .controls {
    grid-template-columns: repeat(3, 1fr) auto;
  }

  canvas {
    max-height: none;
    height: min(100%, calc(100dvh - 118px));
  }

  .scorebar,
  .controls {
    gap: 4px;
    padding: 4px 6px;
  }

  .scorebar strong {
    font-size: 0.82rem;
  }

  .label {
    font-size: 0.58rem;
  }

  .meter {
    grid-template-columns: 42px 1fr 48px;
    gap: 4px;
    font-size: 0.72rem;
  }

  progress {
    height: 9px;
  }

  .upgrade,
  .reset-progress {
    min-height: 24px;
    padding: 0 6px;
    font-size: 0.72rem;
  }

}
