:root {
  --bg-1: #0f1724;
  --bg-2: #1d2d45;
  --panel: rgba(11, 21, 34, 0.84);
  --panel-border: rgba(255, 255, 255, 0.18);
  --text: #f2f6fc;
  --muted: rgba(242, 246, 252, 0.72);
  --accent: #7ee787;
  --danger: #ff7b72;
  --slot-bg: rgba(255, 255, 255, 0.06);
  --slot-selected: rgba(126, 231, 135, 0.3);
  --slot-selected-border: rgba(126, 231, 135, 0.92);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 8% 12%, rgba(126, 231, 135, 0.16), transparent 28%),
    radial-gradient(circle at 91% 16%, rgba(139, 204, 255, 0.2), transparent 34%),
    linear-gradient(155deg, var(--bg-1), var(--bg-2));
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  padding: 10px 12px;
  cursor: pointer;
}

button:hover {
  background: rgba(255, 255, 255, 0.14);
}

.top-actions a {
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  padding: 10px 12px;
  text-decoration: none;
}

.top-actions a:hover {
  background: rgba(255, 255, 255, 0.14);
}

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

input {
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  padding: 9px 11px;
  text-transform: uppercase;
}

.app {
  width: min(1220px, 100%);
  margin: 0 auto;
  padding: 14px;
  display: grid;
  gap: 12px;
}

.top-bar,
.selection-panel,
.overlay-panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  backdrop-filter: blur(5px);
}

.top-bar {
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.top-bar h1 {
  margin: 0;
  font-size: clamp(22px, 3vw, 32px);
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.status-line {
  margin: 0;
}

.status-line.muted {
  color: var(--muted);
  font-size: 14px;
}

.arena-shell {
  display: block;
}

.arena-frame {
  position: relative;
  background: rgba(6, 14, 24, 0.7);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  overflow: hidden;
  aspect-ratio: 1000 / 420;
  min-height: 0;
}

#arena {
  width: 100%;
  height: auto;
  aspect-ratio: 1000 / 420;
  display: block;
}

.app.portrait-arena .arena-frame {
  aspect-ratio: var(--arena-portrait-ratio, 0.6666667);
  margin-inline: auto;
  width: min(100%, calc(var(--arena-max-height, 72vh) * var(--arena-portrait-ratio, 0.6666667)));
  max-height: var(--arena-max-height, 72vh);
}

.app.portrait-arena #arena {
  aspect-ratio: var(--arena-portrait-ratio, 0.6666667);
}

.selection-panel {
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.app.selection-side {
  --side-pad: 4px;
  --side-gap: 4px;
  --side-slot-count: calc(var(--ability-count, 4) + 1);
  --side-tile-size: clamp(34px, calc((var(--selection-fit-height) - (var(--side-pad) * 2) - (var(--side-gap) * (var(--side-slot-count) - 1))) / var(--side-slot-count)), 82px);
  --selection-column-width: calc(var(--side-tile-size) + (var(--side-pad) * 2));
  grid-template-columns: minmax(0, 1fr) var(--selection-column-width);
  align-items: stretch;
  --selection-fit-height: 320px;
  --arena-max-height: 320px;
}

.app.selection-side .top-bar {
  grid-column: 1 / -1;
  grid-row: 1;
  padding: 8px 10px;
  gap: 8px;
}

.app.selection-side .top-bar h1 {
  font-size: clamp(16px, 2.2vw, 24px);
}

.app.selection-side .arena-shell {
  grid-column: 1;
  grid-row: 2;
  display: flex;
  align-items: stretch;
  min-height: 0;
}

.app.selection-side .arena-frame {
  margin-inline: auto;
  width: min(100%, calc(var(--arena-max-height) * 2.380952381));
  max-height: var(--arena-max-height);
  min-width: 0;
}

.app.selection-side .selection-panel {
  grid-column: 2;
  grid-row: 2;
  flex-direction: column;
  align-items: stretch;
  justify-content: space-between;
  gap: var(--side-gap);
  padding: var(--side-pad);
  height: var(--selection-fit-height);
  min-height: 0;
}

.slots {
  display: grid;
  gap: 10px;
  flex: 1 1 auto;
  min-width: 0;
}

.app.selection-side .slots {
  display: block;
  min-height: 0;
}

.selection-order {
  display: grid;
  grid-template-columns: repeat(var(--ability-count, 4), minmax(0, 1fr));
  gap: 10px;
}

.app.selection-side .selection-order {
  width: 100%;
  grid-template-columns: 1fr;
  grid-template-rows: repeat(var(--ability-count, 4), var(--side-tile-size));
  gap: var(--side-gap);
  justify-items: center;
  align-content: start;
  height: auto;
}

.app.selection-side .ability-order-item {
  width: var(--side-tile-size);
  height: var(--side-tile-size);
  max-width: none;
  padding: 4px;
  justify-self: center;
  align-self: center;
}

.ability-order-item {
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 9px;
  padding: 6px;
  text-align: center;
  background: rgba(255, 255, 255, 0.06);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 1 / 1;
  min-height: 0;
  cursor: grab;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  transition: transform 160ms ease, opacity 160ms ease, filter 160ms ease, border-color 160ms ease, background 160ms ease;
}

.ability-order-item:disabled {
  cursor: default;
}

.ability-order-item.priority-first {
  transform: scale(1.08);
  border-color: rgba(126, 231, 135, 0.85);
  background: rgba(126, 231, 135, 0.2);
}

.ability-order-item.priority-mid {
  transform: scale(1);
}

.ability-order-item.priority-low {
  transform: scale(0.9);
}

.ability-order-item.priority-last {
  transform: scale(0.8);
  opacity: 0.45;
  filter: grayscale(1);
}

.ability-order-item.drag-target {
  border-color: rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.16) inset;
}

.ability-order-item.dragging {
  opacity: 0.35;
}

.ability-icon {
  width: 92%;
  height: 92%;
  object-fit: contain;
  pointer-events: none;
}

.slot-count {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.selection-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex: 0 0 auto;
}

.app.selection-side .selection-actions {
  justify-content: center;
  align-items: center;
  height: var(--side-tile-size);
}

#lockRoundButton {
  background: rgba(126, 231, 135, 0.22);
  border-color: rgba(126, 231, 135, 0.75);
  width: clamp(76px, 9vw, 96px);
  min-height: clamp(76px, 9vw, 96px);
  padding: 0;
  font-size: clamp(20px, 2.2vw, 30px);
  font-weight: 800;
  line-height: 1;
  text-transform: uppercase;
}

.app.selection-side #lockRoundButton {
  width: var(--side-tile-size);
  min-height: var(--side-tile-size);
  max-height: var(--side-tile-size);
  font-size: clamp(15px, 1.9vw, 22px);
}

.spin-overlay {
  position: absolute;
  left: 8px;
  right: 8px;
  top: 8px;
  bottom: 8px;
  z-index: 15;
  border-radius: 14px;
  background: rgba(5, 12, 20, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.2);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: center;
  column-gap: 44px;
  row-gap: 8px;
  padding: 8px;
}

.spin-side {
  display: grid;
  gap: 8px;
  justify-items: center;
}

.spin-side h2 {
  margin: 0;
  font-size: 14px;
}

.reel-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  width: min(260px, 100%);
}

.reel-cell {
  min-height: 0;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  display: grid;
  place-items: center;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  padding: 2px;
  gap: 0;
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease, box-shadow 180ms ease;
}

.reel-window {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.reel-item {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  transition: transform 80ms linear;
}

.reel-icon {
  width: 90%;
  height: 90%;
  object-fit: contain;
  pointer-events: none;
}

.reel-label {
  display: none;
}

.reel-cell.active {
  border-color: rgba(255, 255, 255, 0.95);
  transform: scale(1.03);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.18) inset;
}

.reel-cell.stopped {
  border-color: rgba(255, 205, 108, 0.9);
  box-shadow: 0 0 0 2px rgba(255, 205, 108, 0.15) inset;
}

.reel-cell.type-shield {
  background: rgba(66, 157, 255, 0.3);
}

.reel-cell.type-attack {
  background: rgba(255, 99, 93, 0.3);
}

.reel-cell.type-minibots {
  background: rgba(255, 205, 91, 0.32);
}

.reel-cell.type-emp {
  background: rgba(127, 232, 255, 0.32);
}

.reel-cell.type-energize {
  background: rgba(116, 214, 118, 0.3);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 10, 18, 0.78);
  display: grid;
  place-items: start center;
  padding: 16px;
  overflow-y: auto;
  z-index: 40;
}

.hidden {
  display: none !important;
}

.overlay-panel {
  width: min(720px, 100%);
  max-height: calc(100dvh - 32px);
  padding: 14px;
  display: grid;
  gap: 10px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.overlay-panel h2,
.overlay-panel h3 {
  margin: 0;
}

.overlay-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.app-version {
  margin: 2px 0 0;
  min-height: 1em;
  text-align: center;
  font-size: 10px;
  opacity: 0.64;
  letter-spacing: 0.2px;
  text-transform: lowercase;
}

.solo-setup {
  display: grid;
  gap: 8px;
  padding: 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.solo-setup-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr);
  align-items: stretch;
}

.solo-setup-grid label {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  margin-top: 2px;
}

.solo-choice-group {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
}

.solo-choice-group .solo-choice-button {
  width: 100%;
}

.solo-choice-button.active {
  border-color: rgba(126, 231, 135, 0.92);
  background: rgba(126, 231, 135, 0.24);
}

.join-box {
  display: grid;
  gap: 6px;
}

.join-row {
  display: flex;
  gap: 8px;
}

.join-row input {
  width: 110px;
}

.public-rooms {
  display: grid;
  gap: 6px;
}

.public-list {
  display: grid;
  gap: 6px;
  max-height: 170px;
  overflow: auto;
}

.public-room-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  padding: 7px 9px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.public-room-empty {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

@media (max-width: 1080px) and (orientation: portrait) {
  .app {
    width: 100%;
    margin: 0;
    padding: 0;
    gap: 0;
  }

  .top-bar {
    padding: 4px 8px;
    gap: 6px;
  }

  .top-bar h1 {
    font-size: clamp(16px, 3.8vw, 21px);
  }

  .top-actions button {
    padding: 6px 8px;
    border-radius: 8px;
  }

  #lockRoundButton {
    width: clamp(64px, 18vw, 82px);
    min-height: clamp(64px, 18vw, 82px);
    font-size: clamp(18px, 5vw, 24px);
  }

  .selection-order {
    gap: 8px;
  }
}

@media (max-width: 1080px) and (orientation: landscape) {
  .app {
    width: 100%;
    margin: 0;
    padding: 0;
    gap: 0;
  }

  .top-bar {
    padding: 4px 8px;
    gap: 6px;
  }

  .top-bar h1 {
    font-size: clamp(14px, 2.2vw, 18px);
  }

  .top-actions button {
    padding: 5px 8px;
    border-radius: 8px;
  }

  #lockRoundButton {
    width: clamp(56px, 11vw, 76px);
    min-height: clamp(56px, 11vw, 76px);
    font-size: clamp(16px, 2.8vw, 22px);
  }

  .selection-order {
    gap: 8px;
  }
}

@media (max-width: 520px) and (orientation: portrait) {
  .top-actions {
    width: 100%;
  }

  .top-actions button {
    flex: 1 1 auto;
  }

  .selection-panel {
    gap: 8px;
  }

  #lockRoundButton {
    width: clamp(58px, 17vw, 74px);
    min-height: clamp(58px, 17vw, 74px);
    font-size: clamp(16px, 5vw, 22px);
  }

  .spin-overlay {
    left: 4px;
    right: 4px;
    top: 4px;
    bottom: 4px;
    padding: 6px;
    column-gap: 18px;
    row-gap: 6px;
  }

  .spin-side h2 {
    font-size: 12px;
  }

  .reel-row {
    gap: 3px;
    width: min(186px, 100%);
  }

  .selection-order {
    gap: 6px;
  }
}
