:root {
  --bg-a: #0b2a1f;
  --bg-b: #104735;
  --panel: #f4edd6;
  --ink: #18231e;
  --accent: #ca9444;
  --danger: #8c2a2a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Trebuchet MS", "Gill Sans", sans-serif;
  background: radial-gradient(circle at 20% 20%, #18624a 0%, #0b2a1f 55%, #071b14 100%);
  color: var(--ink);
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 16px;
  padding: 16px;
}

.table-wrap {
  position: relative;
  border: 2px solid #0d1f19;
  border-radius: 12px;
  overflow: hidden;
  background: linear-gradient(145deg, var(--bg-a), var(--bg-b));
  min-height: 75vh;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: manipulation;
}

.score-toasts {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
}

.score-toast {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 44px;
  font-weight: 900;
  letter-spacing: 1px;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.25), 0 10px 18px rgba(0, 0, 0, 0.35);
  animation: pop-toast 2.2s ease-out forwards;
  white-space: nowrap;
}

.gameover-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(8, 13, 11, 0.66);
  z-index: 20;
  padding: 16px;
}

.gameover-modal.open {
  display: flex;
}

.gameover-card {
  width: min(520px, 96vw);
  background: linear-gradient(160deg, #fff6de, #eed9a7);
  border: 2px solid #8e784a;
  border-radius: 14px;
  padding: 16px 16px 20px;
  text-align: center;
  box-shadow: 0 14px 42px rgba(0, 0, 0, 0.35);
  color: #312314;
}

.gameover-card h2 {
  margin: 0;
  font-size: 2rem;
}

.gameover-final {
  margin: 8px 0 10px;
  font-weight: 700;
  font-size: 1.05rem;
}

.gameover-skunk-img {
  width: min(260px, 72vw);
  max-height: 200px;
  object-fit: contain;
  display: none;
  margin: 4px auto 8px;
}

.gameover-skunk-text {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 800;
  color: #574018;
}

#gameover-new-btn {
  margin-top: 12px;
  min-width: 170px;
  background: #e7f8e3;
}

.score-toast.player {
  color: #ffe27b;
}

.score-toast.ai {
  color: #9fd3ff;
}

.score-toast.cut {
  font-size: 38px;
  color: #fff7c2;
  text-shadow: 0 3px 0 rgba(72, 52, 13, 0.35), 0 9px 16px rgba(0, 0, 0, 0.35);
}

.score-toast .reason {
  display: block;
  margin-top: 2px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.4px;
  opacity: 0.92;
}

@keyframes pop-toast {
  0% {
    opacity: 0;
    transform: translate(-50%, -42%) scale(0.72) rotate(-2deg);
  }
  18% {
    opacity: 1;
    transform: translate(-50%, -54%) scale(1.06) rotate(1deg);
  }
  78% {
    opacity: 1;
    transform: translate(-50%, -70%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -84%) scale(0.96);
  }
}

.action-row {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: 66%;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 10px;
  background: rgba(7, 22, 17, 0.44);
  backdrop-filter: blur(2px);
}

.task-hud {
  min-width: 310px;
  max-width: 48vw;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(255, 248, 224, 0.9);
  color: #212018;
  border: 1px solid rgba(95, 86, 61, 0.45);
}

.task-label {
  font-size: 0.96rem;
  font-weight: 800;
  line-height: 1.2;
}

.task-meta {
  font-size: 0.82rem;
  margin-top: 2px;
  color: #3e3a2a;
}

.phase-hint {
  font-size: 0.79rem;
  margin-top: 3px;
  color: #5f2b0a;
}

.action-row button {
  min-width: 170px;
  padding: 11px 12px;
}

.score-breakdown {
  margin: 6px 0 10px;
  border: 1px solid #cfbe90;
  border-radius: 8px;
  background: #fff8e0;
  padding: 0 8px 6px;
}

.score-breakdown summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 8px 2px 6px;
}

.score-breakdown-content {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.score-chip {
  display: inline-block;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.78rem;
  font-weight: 700;
  border: 1px solid rgba(0, 0, 0, 0.2);
}

.score-chip.player {
  background: #fff0c9;
  color: #6b4a06;
  border-color: #d8a33a;
}

.score-chip.ai {
  background: #e6efff;
  color: #1d3f8f;
  border-color: #3e63c9;
}

.score-chip.system {
  background: #f4ecda;
  color: #4f442d;
  border-color: #9f8b60;
}

.sidebar {
  background: var(--panel);
  border-radius: 12px;
  padding: 14px;
  border: 1px solid #d6c79a;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 32px);
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 1.35rem;
}

h2 {
  font-size: 1rem;
}

.status {
  margin: 0;
  padding: 8px;
  background: #fff9e8;
  border-left: 4px solid var(--accent);
  border-radius: 4px;
  font-size: 0.95rem;
}

.controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.name-controls {
  display: grid;
  gap: 6px;
}

.name-controls label {
  font-size: 0.85rem;
  font-weight: 700;
  color: #4f442d;
}

.name-controls-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

#player-name-input {
  width: 100%;
  border: 1px solid #8f8159;
  border-radius: 8px;
  padding: 9px 10px;
  font: inherit;
  background: #fffdf3;
  color: var(--ink);
}

button {
  font: inherit;
  border: 1px solid #5f563d;
  background: #fff8e0;
  color: var(--ink);
  border-radius: 8px;
  padding: 10px;
  cursor: pointer;
}

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

#action-btn {
  background: #e7f8e3;
}

.log {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow: auto;
  font-size: 0.9rem;
  line-height: 1.35;
  flex: 1;
}

.log li {
  margin-bottom: 6px;
  padding: 5px 8px;
  border-radius: 6px;
}

.log li.log-player {
  color: #7a560a !important;
  background: #fff4d8;
  border-left: 3px solid #d4a43a;
  font-weight: 600;
}

.log li.log-ai {
  color: #1c3f8f !important;
  background: #edf2ff;
  border-left: 3px solid #3e63c9;
}

.log li.log-system {
  color: #3f3a2c !important;
  background: #f6f0df;
  border-left: 3px solid #8e7a4c;
}

.log .warning {
  color: var(--danger) !important;
}

@media (max-width: 960px) {
  .app {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    min-height: 58vh;
  }

  .sidebar {
    max-height: none;
  }

  .action-row {
    width: calc(100% - 24px);
    justify-content: center;
    gap: 8px;
  }

  .task-hud {
    min-width: 0;
    max-width: none;
    flex: 1;
  }

  .action-row button {
    min-width: 0;
    width: 45%;
  }

  .score-toast {
    font-size: 34px;
  }
}
