* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #bfeaff;
  color: #18364b;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

#game-root,
#viewport {
  position: fixed;
  inset: 0;
}

#viewport canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: #17384c;
  color: #effcff;
  font-size: 18px;
  font-weight: 800;
}

body:not(.is-loading) .loading-screen {
  display: none;
}

body.is-loading #start-panel,
body.is-loading #hud {
  visibility: hidden;
  pointer-events: none;
}

#start-panel {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(31, 68, 82, 0.32);
  backdrop-filter: blur(6px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

#start-panel[hidden] {
  display: none;
}

.start-box {
  width: min(560px, 100%);
  max-height: calc(100vh - 36px);
  max-height: calc(100svh - 36px);
  max-height: calc(100dvh - 36px);
  padding: 22px;
  border: 1px solid rgba(103, 164, 194, 0.42);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 22px 52px rgba(34, 91, 117, 0.28);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.start-kicker {
  margin: 0 0 8px;
  color: #2d6d87;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.start-box h1 {
  margin: 0 0 12px;
  max-width: 100%;
  overflow: hidden;
  color: #102f42;
  font-size: 2rem;
  line-height: 1.05;
  white-space: nowrap;
}

.start-copy {
  margin: 0 0 10px;
  color: #365e70;
  line-height: 1.45;
}

.start-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0 0;
}

.start-controls div {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid rgba(53, 107, 130, 0.18);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.48);
}

.start-controls dt {
  color: #102f42;
  font-size: 12px;
  font-weight: 850;
}

.start-controls dd {
  margin: 3px 0 0;
  color: #365e70;
  font-size: 12px;
  line-height: 1.35;
}

.mode-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 220px));
  justify-content: center;
  gap: 10px;
  margin-top: 18px;
}

.mode-actions button {
  min-height: 44px;
  background: #35b86e;
  color: #082719;
  font-weight: 850;
}

.mode-actions button:nth-child(2) {
  background: #35b86e;
  color: #082719;
}

.gameblocks-credit {
  margin: 18px 0 0;
  color: rgba(16, 47, 66, 0.64);
  font-size: 12px;
  line-height: 1.2;
  text-align: center;
}

.gameblocks-credit a {
  color: inherit;
  font-weight: 850;
  text-decoration: underline;
  text-underline-offset: 2px;
}

#hud {
  position: fixed;
  left: 18px;
  right: 18px;
  bottom: 18px;
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(330px, 1.2fr) auto;
  gap: 12px;
  align-items: end;
  pointer-events: none;
}

.status-row,
.panel,
#message {
  pointer-events: auto;
  border: 1px solid rgba(103, 164, 194, 0.36);
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 14px 34px rgba(60, 125, 156, 0.22);
  backdrop-filter: blur(14px);
}

.status-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  min-height: 74px;
  padding: 11px;
  border-radius: 8px;
  align-content: center;
  color: #466b7d;
}

.status-row span {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 7px;
  white-space: nowrap;
}

.status-row strong {
  display: inline;
  margin-top: 0;
  color: #123247;
  font-size: 1.16rem;
}

.tower-panel {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 8px;
  border-radius: 8px;
}

.tower-card {
  min-height: 58px;
  padding: 8px;
  text-align: left;
  background: rgba(255, 255, 255, 0.52);
  border: 1px solid rgba(118, 176, 199, 0.26);
}

.tower-card:hover,
.tower-card.selected {
  border-color: #35b86e;
  background: rgba(115, 214, 134, 0.34);
}

.tower-name,
.tower-meta {
  display: block;
  line-height: 1.18;
}

.tower-name {
  font-weight: 800;
}

.tower-meta {
  margin-top: 5px;
  color: #5b7480;
  font-size: 0.78rem;
}

.action-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  width: 142px;
  padding: 8px;
  border-radius: 8px;
}

.action-panel button {
  min-height: 29px;
  background: #e4bc58;
  color: #171717;
  font-weight: 800;
}

.action-panel button:nth-child(2) {
  background: #74d4dc;
}

.action-panel button:nth-child(3) {
  background: #ea7772;
}

#message {
  position: fixed;
  left: 18px;
  top: 18px;
  max-width: min(520px, calc(100vw - 36px));
  margin: 0;
  padding: 12px 14px;
  border-radius: 8px;
  color: #16384d;
  line-height: 1.35;
}

@media (max-width: 1000px) {
  #viewport {
    bottom: 266px;
  }

  #hud {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .status-row {
    min-height: 47px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .tower-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .action-panel {
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  #viewport {
    bottom: 148px;
  }

  .start-box {
    padding: 18px;
  }

  .start-box h1 {
    font-size: 1.6rem;
  }

  .mode-actions {
    grid-template-columns: 1fr;
  }

  #hud {
    left: 10px;
    right: 10px;
    bottom: 10px;
    gap: 6px;
  }

  .status-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
    min-height: 42px;
    padding: 8px;
    font-size: 0.72rem;
  }

  .status-row span {
    gap: 3px;
  }

  .status-row strong {
    font-size: 0.95rem;
  }

  .tower-panel {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    padding: 6px;
  }

  .tower-card {
    min-height: 52px;
    padding: 7px 6px;
    text-align: center;
  }

  .tower-name {
    font-size: 0.82rem;
  }

  .tower-meta {
    margin-top: 3px;
    font-size: 0.72rem;
  }

  .tower-trait {
    display: none;
  }

  .action-panel {
    padding: 6px;
  }

  .action-panel button {
    min-height: 31px;
  }

  #message {
    left: 10px;
    top: 10px;
    max-width: calc(100vw - 20px);
    padding: 10px 12px;
    font-size: 0.88rem;
  }
}

@media (max-width: 1000px) and (max-height: 560px) and (orientation: landscape) {
  #viewport {
    bottom: 78px;
  }

  #hud {
    left: 8px;
    right: 8px;
    bottom: 8px;
    grid-template-columns: minmax(132px, 0.85fr) minmax(0, 1.7fr) minmax(96px, 0.55fr);
    gap: 6px;
    align-items: stretch;
  }

  #hud > * {
    min-width: 0;
  }

  .status-row {
    min-height: 58px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 3px;
    padding: 6px;
    font-size: 0.62rem;
  }

  .status-row span {
    flex-direction: column;
    align-items: center;
    gap: 1px;
    text-align: center;
  }

  .status-row strong {
    font-size: 0.82rem;
  }

  .tower-panel {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 5px;
    padding: 5px;
  }

  .tower-card {
    min-height: 48px;
    padding: 6px 4px;
    text-align: center;
  }

  .tower-name {
    font-size: 0.78rem;
  }

  .tower-meta {
    margin-top: 3px;
    font-size: 0.68rem;
  }

  .tower-trait {
    display: none;
  }

  .action-panel {
    width: 100%;
    grid-template-columns: 1fr;
    gap: 4px;
    padding: 5px;
  }

  .action-panel button {
    min-height: 23px;
    font-size: 0.74rem;
  }

  #message {
    left: 8px;
    top: 8px;
    max-width: min(420px, calc(100vw - 16px));
    padding: 8px 10px;
    font-size: 0.82rem;
  }
}
