:root {
  color-scheme: dark;
  --bg: #101419;
  --panel: #171d24;
  --panel-2: #202832;
  --panel-3: #111820;
  --line: #34404d;
  --text: #f3f0e8;
  --muted: #aeb7c2;
  --red: #ff4655;
  --cyan: #5ee4d6;
  --blue: #509cff;
  --green: #7ee787;
  --amber: #f0c36a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(255, 70, 85, 0.12), transparent 34%),
    linear-gradient(315deg, rgba(94, 228, 214, 0.08), transparent 28%),
    var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.randomizer-app {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 18px;
}

.topbar h1 {
  margin-bottom: 8px;
  font-size: clamp(30px, 4vw, 46px);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--red);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
}

.lead,
.hint,
.status,
.empty-result {
  color: var(--muted);
}

.ghost-button,
.tabs button,
.secondary,
.mode-switch button,
button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: var(--panel-2);
  padding: 9px 13px;
  font-weight: 800;
  text-decoration: none;
}

button:not(.secondary):not(.agent-toggle):not(.map-card):not(.map-card-main):not(.draw-card):not(.start-button):not(.reroll-button):not(.tabs button):not(.mode-switch button),
.tabs button.active,
.mode-switch button.active {
  border-color: var(--red);
  background: var(--red);
  color: #fff;
}

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

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: #0d1116;
  padding: 10px 11px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}

.tabs button {
  min-width: 140px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.tool-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 20px;
}

.map-layout {
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
}

.panel {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(23, 29, 36, 0.96);
}

.stack {
  display: grid;
  gap: 16px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
}

.panel-head h2 {
  margin-bottom: 0;
}

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

.map-pool {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
}

.map-card {
  position: relative;
  min-height: 164px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: white;
  background: #0d1116;
  padding: 0;
  text-align: left;
}

.map-card-main {
  position: relative;
  width: 100%;
  min-height: 112px;
  display: block;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  color: white;
  background: transparent;
  padding: 0;
  text-align: left;
}

.map-card img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.42;
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.map-card strong,
.map-card span {
  position: relative;
  z-index: 1;
  display: block;
}

.map-card strong {
  padding: 64px 12px 4px;
  font-size: 17px;
}

.map-card span {
  padding: 0 12px 12px;
  color: var(--muted);
  font-size: 12px;
}

.map-card.active {
  border-color: var(--cyan);
  box-shadow: inset 0 0 0 1px var(--cyan);
}

.map-card.active img {
  opacity: 0.7;
}

.map-card:not(.active) img {
  filter: grayscale(0.85);
}

.vote-control {
  display: grid;
  grid-template-columns: auto minmax(72px, 1fr);
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  background: rgba(13, 17, 22, 0.94);
  font-size: 12px;
  font-weight: 900;
}

.vote-control input {
  min-height: 34px;
  padding: 7px 9px;
  text-align: right;
  font-weight: 900;
}

.result-panel {
  position: sticky;
  top: 20px;
  align-self: start;
  min-height: 320px;
}

.map-result-card {
  display: grid;
  gap: 14px;
}

.map-result-card.is-spinning img {
  animation: mapSpinFlash 0.18s ease;
}

.map-result-card img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.map-result-card h2 {
  margin: 0;
  font-size: clamp(28px, 5vw, 54px);
}

.map-result-meta {
  margin: 6px 0 0;
  color: var(--muted);
  font-weight: 800;
}

@keyframes mapSpinFlash {
  from {
    opacity: 0.55;
    transform: scale(1.02);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

.player-list {
  display: grid;
  gap: 10px;
}

.player-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(170px, 220px) 128px;
  gap: 10px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-3);
}

.rank-select-wrap {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 8px;
  align-items: center;
}

.rank-select-wrap img,
.rank-badge {
  width: 34px;
  height: 34px;
  object-fit: contain;
}

.no-duelist-check {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: #0d1116;
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 800;
}

.no-duelist-check input {
  width: auto;
}

.ocr-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111820;
}

.ocr-panel .panel-head h2 {
  margin: 0;
  font-size: 18px;
}

.ocr-grid {
  display: grid;
  grid-template-columns: minmax(160px, 220px) 1fr;
  gap: 12px;
  align-items: stretch;
}

.ocr-drop {
  min-height: 76px;
  display: grid;
  align-content: center;
  gap: 5px;
  border: 1px dashed rgba(94, 228, 214, 0.58);
  border-radius: 8px;
  color: var(--text);
  background: rgba(94, 228, 214, 0.08);
  padding: 12px;
  outline: none;
}

.ocr-drop.dragging,
.ocr-drop:focus-visible {
  border-color: var(--cyan);
  box-shadow: inset 0 0 0 1px var(--cyan);
}

.ocr-drop span {
  color: var(--muted);
  font-size: 12px;
}

.ocr-preview {
  display: grid;
  justify-items: start;
}

.ocr-preview img {
  width: min(420px, 100%);
  max-height: 220px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d1116;
}

.ocr-candidates {
  display: grid;
  gap: 10px;
}

.ocr-candidate-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
}

.ocr-candidate-head span {
  color: var(--muted);
  font-size: 12px;
}

.ocr-name-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.draw-settings {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.mode-switch {
  display: flex;
  gap: 8px;
}

.status {
  min-height: 22px;
  margin: 0;
}

.status.error {
  color: #ff8c96;
}

.agent-exclude-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(82px, 1fr));
  gap: 8px;
  max-height: 72vh;
  overflow: auto;
  padding-right: 3px;
}

.agent-toggle {
  min-height: 98px;
  display: grid;
  gap: 5px;
  justify-items: center;
  align-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #0d1116;
  padding: 7px;
}

.agent-toggle img {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  object-fit: cover;
}

.agent-toggle span {
  width: 100%;
  overflow-wrap: anywhere;
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.14;
}

.agent-toggle.excluded {
  border-color: #7b2b34;
  background: rgba(255, 70, 85, 0.12);
}

.agent-toggle.excluded img {
  filter: grayscale(1);
  opacity: 0.48;
}

.result-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}

.draw-card {
  display: block;
  width: 100%;
  min-width: 0;
  perspective: 900px;
  min-height: 278px;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
}

.draw-card:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 4px;
}

.draw-card-inner {
  display: block;
  position: relative;
  width: 100%;
  min-height: 278px;
  transition: transform 0.42s ease;
  transform-style: preserve-3d;
}

.draw-card.revealed .draw-card-inner {
  transform: rotateY(180deg);
}

.draw-face {
  position: absolute;
  inset: 0;
  width: 100%;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 9px;
  min-height: 278px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-3);
  padding: 14px;
  backface-visibility: hidden;
}

.draw-front {
  transform: rotateY(180deg);
  border-color: rgba(94, 228, 214, 0.62);
}

.draw-face img.agent-portrait {
  width: 92px;
  height: 92px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--panel-2);
}

.draw-face h3 {
  margin: 0;
  text-align: center;
  font-size: 18px;
}

.draw-face p {
  margin: 0;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.role-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 9px;
  color: var(--muted);
  background: #0d1116;
  font-size: 12px;
  font-weight: 900;
}

.reroll-button {
  min-height: 34px;
  border: 1px solid var(--cyan);
  border-radius: 6px;
  color: #0e1a1d;
  background: var(--cyan);
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 900;
}

.reroll-button:hover {
  filter: brightness(1.08);
}

.reroll-note {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: #0d1116;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 900;
}

.role-duelist {
  border-color: rgba(255, 70, 85, 0.72);
  color: #ffb8bf;
}

.role-initiator {
  border-color: rgba(240, 195, 106, 0.72);
  color: #f7d792;
}

.role-controller {
  border-color: rgba(94, 228, 214, 0.72);
  color: #9af2e9;
}

.role-sentinel {
  border-color: rgba(80, 156, 255, 0.72);
  color: #a9cfff;
}

.amida-controls {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) minmax(150px, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.amida-area {
  display: grid;
  gap: 12px;
}

.start-grid,
.amida-bottom-grid {
  position: relative;
  width: 100%;
}

.start-grid {
  height: 44px;
}

.amida-bottom-grid {
  height: 112px;
}

.start-button {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: #0d1116;
  padding: 8px;
  font-weight: 900;
}

.start-button:hover,
.start-button.active {
  border-color: var(--cyan);
  box-shadow: inset 0 0 0 1px var(--cyan);
}

.amida-scroll {
  overflow-x: auto;
  padding-bottom: 6px;
}

.amida-stage {
  min-width: 680px;
  margin: 0 auto;
  display: grid;
  gap: 10px;
}

.amida-svg {
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d1116;
}

.ladder-line {
  stroke: rgba(174, 183, 194, 0.42);
  stroke-width: 4;
  stroke-linecap: round;
}

.ladder-path {
  fill: none;
  stroke: var(--red);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 7px rgba(255, 70, 85, 0.45));
}

.bottom-agent {
  position: absolute;
  top: 0;
  width: 92px;
  transform: translateX(-50%);
  display: grid;
  gap: 5px;
  justify-items: center;
  align-content: center;
  min-height: 106px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-3);
  padding: 8px;
}

.bottom-agent.result {
  border-color: var(--cyan);
  box-shadow: inset 0 0 0 1px var(--cyan);
}

.bottom-agent img {
  width: 52px;
  height: 52px;
  border-radius: 7px;
  object-fit: cover;
}

.bottom-agent span {
  width: 100%;
  overflow-wrap: anywhere;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  line-height: 1.14;
}

.amida-result {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid rgba(94, 228, 214, 0.5);
  border-radius: 8px;
  background: rgba(94, 228, 214, 0.1);
}

.amida-result img {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  object-fit: cover;
}

.amida-result strong {
  font-size: 20px;
}

@media (max-width: 980px) {
  .randomizer-app {
    padding: 18px;
  }

  .topbar,
  .tool-layout,
  .panel-head,
  .draw-settings {
    display: block;
  }

  .ghost-button,
  .actions,
  .side-panel,
  .result-panel,
  .panel-head > .actions {
    margin-top: 12px;
  }

  .result-panel {
    position: static;
  }

  .player-row,
  .ocr-grid,
  .amida-controls {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 620px) {
  .tabs,
  .mode-switch,
  .actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .map-pool {
    grid-template-columns: 1fr;
  }
}
