:root {
  --ink: #17202a;
  --muted: #667085;
  --snow: #f5f7fb;
  --ice: #dff3f7;
  --blue: #1677a7;
  --red: #d75f48;
  --gold: #d49a36;
  --wood: #8f5a2d;
  --line: rgba(23, 32, 42, 0.16);
  --shadow: 0 18px 45px rgba(21, 33, 48, 0.18);
}

* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
  font-family:
    Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(180deg, #f0f7fa 0%, #fffaf0 58%, #f2f4f7 100%);
}

button {
  font: inherit;
}

.app {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right))
    max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}

.game-shell {
  width: min(1180px, 100%);
  height: min(720px, calc(100vh - 28px));
  min-height: 540px;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 74px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.74);
  backdrop-filter: blur(12px);
}

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

.brand strong,
.brand span {
  display: block;
  white-space: nowrap;
}

.brand strong {
  font-size: 19px;
  line-height: 1.15;
}

.brand span:not(.mark) {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.mark {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 8px;
  background:
    linear-gradient(135deg, transparent 43%, rgba(255, 255, 255, 0.7) 44% 56%, transparent 57%),
    linear-gradient(135deg, #166d8f, #f0b94f 72%, #b84632);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.56);
}

.scoreboard {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.scoreboard span {
  min-width: 66px;
  padding: 8px 10px;
  text-align: center;
  border: 1px solid rgba(23, 32, 42, 0.12);
  border-radius: 8px;
  background: #ffffff;
  font-weight: 800;
}

#timerLabel {
  min-width: 50px;
  color: #8a3b2d;
}

.help-btn {
  width: 38px;
  height: 38px;
  border: 1px solid rgba(23, 32, 42, 0.12);
  border-radius: 8px;
  background: #ffffff;
  color: var(--blue);
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(21, 33, 48, 0.1);
}

.playfield {
  position: relative;
  min-height: 0;
  overflow: hidden;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

#gameCanvas.is-pulling {
  cursor: grabbing;
}

.arena-hint {
  position: absolute;
  left: 50%;
  top: 96px;
  transform: translateX(-50%);
  width: min(420px, calc(100% - 36px));
  padding: 10px 14px;
  border: 1px solid rgba(23, 32, 42, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  text-align: center;
  box-shadow: 0 12px 28px rgba(21, 33, 48, 0.12);
  pointer-events: none;
}

.arena-hint strong,
.arena-hint span {
  display: block;
}

.arena-hint strong {
  color: var(--ink);
  font-size: 16px;
  line-height: 1.2;
}

.arena-hint span {
  margin-top: 3px;
  color: #465562;
  font-size: 13px;
}

.arena-hint.is-muted {
  opacity: 0.18;
}

.arena-hint.is-hidden {
  display: none;
}

.attack-signal {
  position: absolute;
  left: 68%;
  top: 30%;
  z-index: 7;
  min-width: 112px;
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(180deg, #ffef5a, #ff5b35);
  color: #ffffff;
  font-size: 20px;
  font-weight: 1000;
  letter-spacing: 0;
  text-shadow: 0 2px 8px rgba(90, 18, 10, 0.34);
  box-shadow: 0 14px 34px rgba(214, 57, 40, 0.34);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0.82);
  transition: opacity 120ms ease, transform 120ms ease;
  touch-action: manipulation;
}

.attack-signal.is-visible {
  opacity: 1;
  pointer-events: auto;
  animation: attackSignalPulse 520ms ease-in-out infinite;
}

.attack-signal:active {
  transform: translate(-50%, -50%) scale(0.96);
}

.training-exit {
  position: absolute;
  right: 18px;
  top: 18px;
  z-index: 9;
  display: flex;
  gap: 8px;
  align-items: center;
}

.training-exit[hidden] {
  display: none;
}

.mini-action {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid rgba(23, 32, 42, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 10px 24px rgba(21, 33, 48, 0.14);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-size: 13px;
  font-weight: 900;
  text-decoration: none;
  touch-action: manipulation;
}

.mini-action.ghost {
  color: var(--blue);
}

.mini-action:active {
  transform: translateY(1px);
}

.coach-panel {
  position: absolute;
  left: 18px;
  top: 18px;
  width: min(440px, calc(100% - 36px));
  padding: 12px 14px;
  border: 1px solid rgba(23, 32, 42, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 12px 28px rgba(21, 33, 48, 0.14);
  pointer-events: none;
}

.coach-panel strong,
.coach-panel span,
.coach-panel small {
  display: block;
}

.coach-panel strong {
  color: var(--blue);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.coach-panel span {
  margin-top: 4px;
  font-size: 18px;
  font-weight: 900;
  line-height: 1.2;
}

.coach-panel small {
  margin-top: 5px;
  color: #465562;
  font-size: 13px;
  line-height: 1.35;
}

.hud {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 112px;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(210px, 0.8fr) minmax(240px, 1fr);
  align-items: end;
  gap: 14px;
  pointer-events: none;
}

.tug-track,
.meter,
.stat-grid {
  padding: 12px;
  border: 1px solid rgba(23, 32, 42, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 8px 24px rgba(21, 33, 48, 0.12);
}

.tug-track {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 800;
}

.tug-line {
  position: relative;
  height: 12px;
  border-radius: 999px;
  background:
    linear-gradient(90deg, rgba(22, 119, 167, 0.95), rgba(255, 255, 255, 0.8) 50%, rgba(215, 95, 72, 0.95)),
    #ffffff;
  outline: 1px solid rgba(23, 32, 42, 0.12);
}

.tug-line::after {
  content: "";
  position: absolute;
  left: 50%;
  top: -5px;
  width: 2px;
  height: 22px;
  background: rgba(23, 32, 42, 0.35);
}

.tug-line i,
.timing-bar i {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  display: block;
  width: 18px;
  height: 18px;
  border: 3px solid #ffffff;
  border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 5px 12px rgba(23, 32, 42, 0.24);
}

.meter-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
  font-size: 13px;
}

.meter-title span {
  color: var(--muted);
}

.meter-title strong {
  color: var(--blue);
}

.timing-bar {
  position: relative;
  height: 20px;
  border-radius: 999px;
  background: linear-gradient(90deg, #d9dee8, #f4d58c 24%, #f9e7ae 50%, #f4d58c 76%, #d9dee8);
  outline: 1px solid rgba(23, 32, 42, 0.12);
  overflow: visible;
}

.timing-bar b {
  position: absolute;
  left: 40%;
  width: 30%;
  top: -4px;
  height: 28px;
  border: 2px solid rgba(12, 97, 82, 0.78);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(86, 195, 157, 0.72), rgba(33, 151, 127, 0.78));
  box-shadow: 0 5px 16px rgba(33, 151, 127, 0.2);
  transition: left 160ms ease, width 160ms ease;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.stat span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.stat div {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(23, 32, 42, 0.12);
}

.stat i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--red), var(--gold), #34a989);
}

.touch-controls {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 18px;
  display: grid;
  grid-template-columns: minmax(180px, 1.45fr) minmax(136px, 0.9fr);
  gap: 12px;
}

.control-btn,
.menu-btn {
  min-height: 70px;
  border: 0;
  border-radius: 8px;
  color: #ffffff;
  font-weight: 900;
  letter-spacing: 0;
  cursor: pointer;
  box-shadow: 0 12px 26px rgba(21, 33, 48, 0.18);
  transition:
    transform 140ms ease,
    filter 140ms ease;
  touch-action: manipulation;
}

.control-btn:active,
.control-btn.is-held,
.menu-btn:active {
  transform: translateY(2px) scale(0.99);
  filter: brightness(0.96);
}

.control-btn span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  white-space: nowrap;
}

.control-btn small {
  display: block;
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 12px;
  line-height: 1;
}

.hold-control span,
.burst-control span {
  font-size: 20px;
}

.burst-control.is-waiting {
  opacity: 0.7;
  filter: saturate(0.75);
}

.burst-control.is-ready {
  background: linear-gradient(180deg, #ffc04d, #d96639);
  animation: readyPulse 860ms ease-in-out infinite;
}

.burst-control.is-ready span {
  color: #ffffff;
}

@keyframes readyPulse {
  0%,
  100% {
    transform: translateY(0) scale(1);
    box-shadow: 0 12px 26px rgba(217, 102, 57, 0.22);
  }

  50% {
    transform: translateY(-2px) scale(1.025);
    box-shadow: 0 18px 34px rgba(217, 102, 57, 0.34);
  }
}

@keyframes attackSignalPulse {
  0%,
  100% {
    transform: translate(-50%, -50%) scale(0.98);
    box-shadow: 0 14px 34px rgba(214, 57, 40, 0.34);
  }

  50% {
    transform: translate(-50%, -50%) scale(1.12);
    box-shadow: 0 18px 42px rgba(214, 57, 40, 0.5);
  }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.primary {
  background: linear-gradient(180deg, #1c86b6, #0f5c84);
}

.secondary {
  background: linear-gradient(180deg, #45535f, #24303b);
}

.accent {
  background: linear-gradient(180deg, #d99a2e, #b75337);
}

.accent.is-cooling {
  opacity: 0.58;
}

.modal {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(8, 18, 28, 0.42);
  backdrop-filter: blur(5px);
}

.modal.is-open {
  display: grid;
}

.modal-panel {
  width: min(620px, 100%);
  max-height: calc(100dvh - 36px);
  overflow: auto;
  padding: 26px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(245, 247, 251, 0.95)),
    #ffffff;
  box-shadow: var(--shadow);
}

.modal-panel p,
.modal-panel h1 {
  margin: 0;
}

#modalKicker {
  color: var(--blue);
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

#modalTitle {
  margin-top: 8px;
  font-size: clamp(30px, 6vw, 46px);
  line-height: 1.02;
  letter-spacing: 0;
}

#modalText {
  margin-top: 14px;
  color: #40505c;
  font-size: 16px;
  line-height: 1.55;
}

.modal-guide {
  display: none;
  margin-top: 16px;
  border-top: 1px solid rgba(23, 32, 42, 0.12);
  border-bottom: 1px solid rgba(23, 32, 42, 0.12);
}

.modal-guide.has-items {
  display: block;
}

.guide-row {
  display: grid;
  grid-template-columns: 104px 1fr;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid rgba(23, 32, 42, 0.1);
}

.guide-row:first-child {
  border-top: 0;
}

.guide-row strong {
  color: var(--blue);
  font-size: 13px;
}

.guide-row span {
  color: #364653;
  font-size: 14px;
  line-height: 1.35;
}

.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
}

.menu-btn {
  min-height: 48px;
  padding: 0 18px;
  background: linear-gradient(180deg, #1677a7, #0f5c84);
}

.menu-btn.ghost {
  color: var(--ink);
  background: #ffffff;
  border: 1px solid rgba(23, 32, 42, 0.16);
  box-shadow: none;
}

.map-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

@media (max-width: 820px) {
  .app {
    padding: 0;
  }

  .game-shell {
    width: 100%;
    height: 100dvh;
    min-height: 0;
    border-radius: 0;
    border: 0;
  }

  .topbar {
    min-height: 66px;
    padding: 10px 12px;
  }

  .brand strong {
    max-width: 42vw;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 15px;
  }

  .brand span:not(.mark) {
    max-width: 42vw;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 11px;
  }

  .mark {
    width: 34px;
    height: 34px;
  }

  .scoreboard {
    gap: 6px;
  }

  .scoreboard span {
    min-width: 48px;
    padding: 7px 8px;
    font-size: 12px;
  }

  .help-btn {
    width: 34px;
    height: 34px;
  }

  .coach-panel {
    left: 10px;
    top: 72px;
    width: calc(100% - 20px);
    padding: 10px 11px;
  }

  .arena-hint {
    top: 12px;
    width: calc(100% - 20px);
    padding: 8px 10px;
  }

  .arena-hint strong {
    font-size: 13px;
  }

  .arena-hint span {
    font-size: 11px;
  }

  .training-exit {
    right: 10px;
    top: 112px;
    gap: 6px;
  }

  .mini-action {
    min-height: 36px;
    padding: 0 10px;
    font-size: 12px;
  }

  .coach-panel span {
    font-size: 15px;
  }

  .coach-panel small {
    font-size: 12px;
  }

  .hud {
    left: 10px;
    right: 10px;
    bottom: 96px;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .stat-grid {
    display: none;
  }

  .tug-track,
  .meter {
    padding: 9px;
  }

  .touch-controls {
    left: 10px;
    right: 10px;
    bottom: 10px;
    gap: 8px;
  }

  .control-btn {
    min-height: 82px;
    font-size: 15px;
  }

  .hold-control span,
  .burst-control span {
    font-size: 18px;
  }

  .attack-signal {
    min-width: 96px;
    min-height: 42px;
    font-size: 17px;
  }

  .control-btn small {
    font-size: 10px;
  }

  .modal-panel {
    max-height: calc(100dvh - 24px);
    padding: 22px;
  }

  .guide-row {
    grid-template-columns: 1fr;
    gap: 3px;
  }

  .modal-actions {
    flex-direction: column;
  }
}

@media (max-height: 560px) and (orientation: landscape) {
  .topbar {
    min-height: 54px;
    padding: 7px 12px;
  }

  .brand span:not(.mark) {
    display: none;
  }

  .coach-panel {
    top: 8px;
    width: min(360px, calc(100% - 20px));
  }

  .arena-hint {
    display: none;
  }

  .training-exit {
    right: 10px;
    top: 8px;
  }

  .mini-action {
    min-height: 34px;
    padding: 0 9px;
    font-size: 11px;
  }

  .hud {
    bottom: 78px;
    grid-template-columns: 1fr 1fr;
  }

  .stat-grid {
    display: none;
  }

  .touch-controls {
    bottom: 8px;
  }

  .control-btn {
    min-height: 58px;
  }

  .control-btn small {
    display: none;
  }
}
