:root {
  --page-bg: linear-gradient(180deg, #f3d287, #d15f4f);
  --chroma-bg: #00b140;
  --text: #261710;
  --muted: #6d524a;
  --accent: #cd4d2d;
  --accent-dark: #7e2518;
  --panel: rgba(255, 248, 236, 0.94);
  --tile-bg: rgba(255, 249, 234, 0.96);
  --tile-border: rgba(107, 56, 24, 0.18);
  --shadow: 0 22px 48px rgba(73, 23, 14, 0.18);
  --player-1: #cd4d2d;
  --player-2: #1d67b2;
  --player-3: #20875f;
  --player-4: #7f43e6;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Pretendard", sans-serif;
  color: var(--text);
  background: var(--page-bg);
}

body.chroma-mode {
  background: var(--chroma-bg);
}

button,
input,
textarea,
select {
  font: inherit;
}

h2 {
  margin: 0;
  font-family: "Black Han Sans", sans-serif;
  font-weight: 400;
  letter-spacing: 0.01em;
}

.app-shell {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
}

.broadcast-layout {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.board-stage {
  position: relative;
  width: min(1600px, calc(100vw - 48px));
  aspect-ratio: 10 / 6;
}

.board {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(10, minmax(92px, 1fr));
  grid-template-rows: repeat(6, minmax(92px, 1fr));
  gap: 12px;
  padding: 14px;
}

.board-spacer {
  pointer-events: none;
}

.board-mover {
  position: absolute;
  left: 0;
  top: 0;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.96);
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.18);
  transform: translate(-50%, -50%);
  z-index: 6;
  pointer-events: none;
}

.board-mover.hidden {
  opacity: 0;
}

.tile {
  position: relative;
  padding: 14px 12px 64px;
  border: 1px solid var(--tile-border);
  border-radius: 22px;
  background: var(--tile-bg);
  box-shadow: var(--shadow);
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  overflow: hidden;
  transition:
    transform 180ms ease,
    box-shadow 180ms ease,
    border-color 180ms ease;
}

.tile:hover {
  transform: translateY(-2px);
  border-color: rgba(107, 56, 24, 0.34);
}

.tile.active {
  border-color: rgba(205, 77, 45, 0.6);
  box-shadow:
    var(--shadow),
    0 0 0 3px rgba(205, 77, 45, 0.16);
}

.tile-index {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent-dark);
}

.tile-title {
  font-size: 1.04rem;
  font-weight: 700;
}

.tile-description {
  font-size: 0.92rem;
  line-height: 1.45;
  color: var(--muted);
}

.tile-tokens {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  max-width: calc(100% - 20px);
}

.token {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.16);
}

.token.image-token,
.player-marker.has-image,
.board-mover.has-image {
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

.dice-panel {
  position: absolute;
  left: calc(10% + 18px);
  bottom: calc(16.666% + 16px);
  width: min(320px, 23%);
  padding: 18px;
  border-radius: 28px;
  background: rgba(255, 249, 239, 0.92);
  box-shadow: var(--shadow);
  z-index: 2;
}

.dice {
  width: min(150px, 100%);
  aspect-ratio: 1;
  margin: 0 auto 16px;
  border-radius: 30px;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.95), rgba(255, 231, 190, 0.95)),
    #fff;
  box-shadow:
    inset 0 -12px 18px rgba(205, 77, 45, 0.1),
    0 18px 28px rgba(87, 30, 16, 0.15);
}

.dice.rolling {
  animation: shake 650ms ease;
}

.dice-value {
  font-family: "Black Han Sans", sans-serif;
  font-size: 4rem;
  line-height: 1;
}

.roll-button,
.ghost-button,
.settings-toggle {
  border: none;
  border-radius: 16px;
  padding: 12px 16px;
  cursor: pointer;
  transition:
    transform 160ms ease,
    opacity 160ms ease,
    background-color 160ms ease;
}

.roll-button {
  width: 100%;
  background: linear-gradient(180deg, #e16749, var(--accent));
  color: #fff8f3;
  font-weight: 700;
}

.ghost-button {
  background: rgba(255, 255, 255, 0.84);
  color: var(--text);
  font-weight: 600;
}

.icon-button {
  padding: 10px 14px;
}

.full-width {
  width: 100%;
}

.roll-button:hover,
.ghost-button:hover,
.settings-toggle:hover {
  transform: translateY(-1px);
}

.roll-button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.turn-label,
.result-label,
.player-status {
  color: var(--muted);
}

.turn-label,
.result-label {
  margin: 12px 0 0;
  line-height: 1.45;
}

.settings-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 30;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: rgba(255, 248, 235, 0.94);
  box-shadow: var(--shadow);
  font-size: 1.5rem;
}

.settings-panel {
  position: fixed;
  top: 90px;
  right: 20px;
  width: min(360px, calc(100vw - 40px));
  max-height: calc(100vh - 110px);
  overflow: auto;
  padding: 18px;
  border-radius: 28px;
  background: rgba(255, 247, 232, 0.96);
  box-shadow: var(--shadow);
  z-index: 25;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.settings-panel.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
  margin-bottom: 16px;
}

.card-kicker {
  margin: 0 0 8px;
  color: var(--accent-dark);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.76rem;
}

.settings-card {
  padding: 16px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.74);
}

.settings-card + .settings-card {
  margin-top: 14px;
}

.player-count,
.field {
  display: grid;
  gap: 8px;
}

.field + .field {
  margin-top: 12px;
}

.player-count select,
.field input,
.field textarea {
  width: 100%;
  border: 1px solid rgba(107, 56, 24, 0.18);
  border-radius: 16px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.92);
}

.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
}

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

.player-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.82);
}

.player-marker {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.7);
}

.player-info {
  min-width: 0;
  flex: 1;
}

.player-status {
  margin: 4px 0 0;
  font-size: 0.92rem;
}

.upload-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.92);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.player-image-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.stack-actions {
  display: grid;
  gap: 10px;
}

.edit-dialog {
  width: min(520px, calc(100% - 24px));
  border: none;
  border-radius: 26px;
  padding: 0;
  box-shadow: var(--shadow);
}

.edit-dialog::backdrop {
  background: rgba(27, 14, 12, 0.42);
  backdrop-filter: blur(3px);
}

.edit-form {
  padding: 24px;
  background: #fff8ef;
}

.dialog-header {
  margin-bottom: 16px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

@keyframes shake {
  0% { transform: rotate(0deg) scale(1); }
  20% { transform: rotate(-8deg) scale(1.02); }
  40% { transform: rotate(7deg) scale(1.01); }
  60% { transform: rotate(-5deg) scale(1.03); }
  80% { transform: rotate(4deg) scale(0.99); }
  100% { transform: rotate(0deg) scale(1); }
}

@media (max-width: 1200px) {
  .board-stage {
    width: min(100vw - 24px, 1400px);
  }

  .board {
    grid-template-columns: repeat(10, minmax(64px, 1fr));
    grid-template-rows: repeat(6, minmax(82px, 1fr));
    gap: 10px;
  }

  .tile {
    padding: 10px 10px 52px;
    border-radius: 18px;
    gap: 6px;
  }

  .tile-index {
    font-size: 0.72rem;
  }

  .tile-title {
    font-size: 0.9rem;
  }

  .tile-description {
    font-size: 0.77rem;
    line-height: 1.3;
  }

  .board-mover {
    width: 40px;
    height: 40px;
  }

  .dice-panel {
    width: min(280px, 28%);
  }
}

@media (max-width: 900px) {
  .broadcast-layout {
    display: block;
    padding: 80px 12px 16px;
    overflow-x: auto;
  }

  .board-stage {
    width: 1380px;
    min-height: auto;
  }

  .dice-panel {
    width: 240px;
  }
}
