* {
  box-sizing: border-box;
}

:root {
  color-scheme: dark;
  --bg: #0f1116;
  --panel: #171b23;
  --panel-2: #1e2430;
  --panel-3: #232c3b;
  --border: #2c3442;
  --border-strong: #4d79d6;
  --text: #eef2f7;
  --muted: #a8b1be;
  --accent: #4f83ff;
  --accent-2: #7aa4ff;
  --good: #16381f;
  --good-border: #2f8250;
  --bad: #431d22;
  --bad-border: #8a3945;
  --shadow: 0 18px 36px rgba(0, 0, 0, 0.35);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top, rgba(79, 131, 255, 0.14), transparent 28%),
    var(--bg);
  color: var(--text);
  font-family: Arial, sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  border-radius: 12px;
  padding: 0.75rem 1rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
  background: var(--accent);
}

button:hover {
  filter: brightness(1.06);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.8rem 0.9rem;
  color: var(--text);
  background: #11161f;
}

.game-shell {
  max-width: 1420px;
  margin: 0 auto;
  padding: 1.5rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.topbar h1,
.panel h2,
.panel h3 {
  margin: 0;
}

.subtitle,
.muted {
  color: var(--muted);
}

.subtitle {
  margin: 0.4rem 0 0;
  max-width: 760px;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.encyclopedia-button {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
}

.encyclopedia-count {
  display: inline-flex;
  align-items: center;
  min-height: 1.8rem;
  padding: 0 0.65rem;
  border-radius: 999px;
  background: rgba(10, 14, 22, 0.28);
}

.status-pill {
  margin-bottom: 1rem;
  padding: 0.8rem 1rem;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--panel);
}

.status-pill[data-state="success"] {
  background: var(--good);
  border-color: var(--good-border);
}

.status-pill[data-state="reward"] {
  background: #2b2148;
  border-color: #9d7dff;
}

.status-pill[data-state="error"] {
  background: var(--bad);
  border-color: var(--bad-border);
}

.main-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 1rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 1rem;
  box-shadow: var(--shadow);
}

.panel-head,
.section-title-row,
.list-summary,
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.sidebar-title-row {
  margin-bottom: 1rem;
}

.sidebar-tabs {
  display: flex;
  gap: 0.65rem;
  margin-bottom: 1rem;
}

.sidebar-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.65rem 0.9rem;
  background: var(--panel-3);
  border: 1px solid var(--border);
}

.sidebar-tab[aria-selected="true"] {
  background: #22304a;
  border-color: var(--accent-2);
}

.sidebar-tab[hidden] {
  display: none;
}

.sidebar-tab-flashing {
  animation: token-tab-flash 1.1s ease-in-out infinite;
}

.sidebar-tab .section-count {
  min-width: 1.8rem;
}

.token-panel-copy {
  margin: 0 0 0.9rem;
}

.token-list {
  display: grid;
  gap: 0.8rem;
}

.token-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  padding: 0.95rem 1rem;
  border-radius: 16px;
  border: 1px solid #6b5ac4;
  background: linear-gradient(180deg, #3a2d63, #241c43);
  text-align: left;
}

.token-button.is-dragging {
  opacity: 0.72;
}

.token-button-copy {
  display: grid;
  gap: 0.22rem;
}

.token-button-title {
  font-weight: 800;
}

.token-button-text {
  color: #d6cdfb;
  font-size: 0.92rem;
}

.token-chip {
  min-width: 2rem;
  padding: 0.26rem 0.6rem;
  border-radius: 999px;
  background: rgba(11, 13, 20, 0.35);
  text-align: center;
  font-weight: 800;
}

@keyframes token-tab-flash {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(157, 125, 255, 0.1);
    border-color: var(--border);
  }
  50% {
    box-shadow: 0 0 0 3px rgba(157, 125, 255, 0.32);
    border-color: #9d7dff;
  }
}

@keyframes floating-match-preview-rise {
  0% {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }

  12% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }

  100% {
    opacity: 0;
    transform: translateY(-26px) scale(1);
  }
}

.google-button {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
}

.google-button[aria-pressed="true"] {
  border-color: #5f8dff;
  background: #20304f;
}

.google-glyph {
  display: inline-flex;
  width: 1.15rem;
  height: 1.15rem;
  color: #9ec0ff;
}

.google-glyph svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.google-glyph rect {
  fill: rgba(79, 131, 255, 0.16);
}

.google-glyph circle {
  fill: rgba(79, 131, 255, 0.08);
}

.playfield-panel {
  min-height: 720px;
}

.ghost-button {
  background: var(--panel-3);
  border: 1px solid var(--border);
}

.playfield {
  position: relative;
  min-height: 620px;
  margin-top: 1rem;
  overflow: hidden;
  border-radius: 18px;
  border: 1px dashed #42506a;
  background:
    linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    #0f1520;
  background-size: 32px 32px;
}

.playfield[data-drag-over="true"] {
  border-color: var(--border-strong);
  box-shadow: inset 0 0 0 1px rgba(122, 164, 255, 0.35);
}

.floating-match-preview {
  position: absolute;
  width: 190px;
  padding: 0.7rem 0.8rem;
  border-radius: 14px;
  border: 1px solid rgba(122, 164, 255, 0.45);
  background: rgba(16, 23, 35, 0.94);
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.34);
  pointer-events: none;
  z-index: 999999;
  animation: floating-match-preview-rise 2s ease-out forwards;
}

.floating-match-preview-title {
  margin-bottom: 0.45rem;
  color: #d6e4ff;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.floating-match-preview-line {
  color: #eef2f7;
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.35;
}

.negative-mix-panel {
  position: absolute;
  top: 1rem;
  left: 1rem;
  width: 280px;
  padding: 0.9rem;
  border-radius: 18px;
  border: 1px solid #4a5670;
  background: rgba(15, 19, 28, 0.94);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
  z-index: 5000;
}

.negative-mix-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.negative-mix-title {
  font-weight: 800;
  font-size: 1rem;
}

.negative-close-button {
  min-width: 2.25rem;
  padding: 0.42rem 0.7rem;
}

.negative-mix-text {
  margin: 0.45rem 0 0.8rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.negative-mix-slots {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.negative-slot {
  min-height: 86px;
  padding: 0.7rem;
  border-radius: 14px;
  border: 1px dashed #536584;
  background: #151c29;
}

.negative-slot[data-drag-over="true"] {
  border-color: var(--accent-2);
  background: #1a2436;
}

.negative-slot-label {
  display: block;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.negative-slot-word {
  display: block;
  margin-top: 0.45rem;
  font-weight: 800;
  word-break: break-word;
}

.negative-slot-word[data-empty="true"] {
  color: #7f8a9a;
  font-weight: 600;
}

.negative-mix-actions {
  display: flex;
  gap: 0.65rem;
  margin-top: 0.8rem;
}

.negative-mix-actions button {
  flex: 1;
}

.playfield-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  text-align: center;
  color: var(--muted);
  pointer-events: none;
}

.playfield-empty[hidden] {
  display: none;
}

.garbage-panel {
  margin-top: 1rem;
}

.garbage-copy {
  margin: 0.35rem 0 0;
}

.garbage-bin {
  margin-top: 0.9rem;
  padding: 1rem 1.1rem;
  border-radius: 18px;
  border: 1px dashed #6f5c3a;
  background: linear-gradient(180deg, #261f16, #1a1712);
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.garbage-bin[data-drag-over="true"] {
  border-color: #d7a962;
  box-shadow: inset 0 0 0 1px rgba(215, 169, 98, 0.28);
  background: linear-gradient(180deg, #31261a, #211b14);
}

.garbage-bin-title {
  font-weight: 800;
}

.garbage-bin-text {
  margin-top: 0.4rem;
  color: #d7c4a6;
  font-size: 0.92rem;
  line-height: 1.45;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sidebar-section {
  padding: 0.9rem;
  border-radius: 16px;
  background: var(--panel-2);
  border: 1px solid var(--border);
}

.word-list {
  display: grid;
  gap: 0.9rem;
}

.word-category {
  padding-top: 0.2rem;
  border-top: 1px solid var(--border);
}

.word-category:first-child {
  border-top: 0;
  padding-top: 0;
}

.word-category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.7rem;
}

.word-category-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
}

.word-category-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0;
  background: transparent;
  border: 0;
  color: var(--text);
  font-weight: 800;
}

.word-category-toggle:hover {
  filter: none;
  color: #ffffff;
}

.word-category-chevron {
  color: var(--muted);
  font-size: 0.82rem;
}

.word-category-count {
  color: var(--muted);
  font-size: 0.88rem;
}

.word-category-delete {
  padding: 0.38rem 0.68rem;
  font-size: 0.82rem;
}

.word-category-dropzone {
  min-height: 48px;
  padding: 0.15rem;
  border-radius: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.word-category-dropzone[data-drag-over="true"] {
  background: rgba(79, 131, 255, 0.08);
  box-shadow: inset 0 0 0 1px rgba(122, 164, 255, 0.25);
}

.word-category-dropzone[hidden] {
  display: none;
}

.search-label {
  display: block;
  margin: 0.8rem 0 0.5rem;
  font-size: 0.95rem;
  color: var(--muted);
}

.source-word {
  padding: 0.6rem 0.8rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #121926;
  color: var(--text);
  font-weight: 700;
}

.source-word:hover {
  border-color: var(--accent-2);
  background: #182133;
}

.source-word:active {
  cursor: grabbing;
}

.source-word[data-kind="discovered"] {
  background: #1f2331;
}

.source-word-empty {
  margin: 0;
  color: var(--muted);
}

.section-count {
  min-width: 2.1rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  text-align: center;
  background: #11161f;
  border: 1px solid var(--border);
  color: var(--muted);
  font-weight: 700;
}

.tile {
  position: absolute;
  width: 152px;
  min-height: 76px;
  padding: 0.8rem 0.85rem;
  border-radius: 16px;
  background: linear-gradient(180deg, #24314a, #192231);
  border: 1px solid #405479;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.3);
  user-select: none;
  cursor: grab;
  touch-action: none;
}

.tile[data-kind="discovered"] {
  background: linear-gradient(180deg, #2d3650, #1e2738);
}

.tile[data-tagged="true"] {
  background: linear-gradient(180deg, #5a3a22, #302113);
  border-color: #d89a52;
  box-shadow: 0 14px 30px rgba(86, 49, 18, 0.42);
}

.tile.dragging {
  cursor: grabbing;
  border-color: var(--accent-2);
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.42);
}

.tile-tag {
  display: inline-flex;
  align-items: center;
  margin-bottom: 0.45rem;
  padding: 0.18rem 0.48rem;
  border-radius: 999px;
  background: rgba(18, 11, 6, 0.4);
  border: 1px solid rgba(255, 204, 138, 0.38);
  color: #ffd9ac;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.tile-tag[hidden] {
  display: none;
}

.tile-word {
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.2;
  word-break: break-word;
}

.tile-meta {
  margin-top: 0.45rem;
  color: #c0c9d6;
  font-size: 0.84rem;
}

.tile-meta[hidden] {
  display: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  z-index: 100000;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-card {
  width: min(1100px, 100%);
  max-height: 85vh;
  overflow: auto;
  border-radius: 22px;
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.settings-modal-card {
  width: min(560px, 100%);
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1rem;
}

.settings-copy {
  margin-bottom: 0;
}

.history-list {
  display: grid;
  gap: 0.7rem;
  margin-top: 1rem;
}

.history-item {
  padding: 0.8rem 0.9rem;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #121826;
}

.history-item-main {
  font-weight: 800;
}

.history-item-meta {
  margin-top: 0.3rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.encyclopedia-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.category-card {
  padding: 0.95rem;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--panel-2);
}

.category-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.8rem;
}

.category-count {
  color: var(--muted);
  font-size: 0.9rem;
}

.category-list {
  display: grid;
  gap: 0.55rem;
}

.encyclopedia-entry {
  padding: 0.6rem 0.75rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #121826;
  font-weight: 700;
}

.encyclopedia-entry[data-discovered="false"] {
  color: #7c8796;
  opacity: 0.82;
}

.encyclopedia-entry[data-discovered="true"] {
  border-color: #476fc7;
  background: #18243b;
}

@media (max-width: 1040px) {
  .main-layout {
    grid-template-columns: 1fr;
  }

  .playfield-panel {
    min-height: 0;
  }
}

@media (max-width: 700px) {
  .game-shell {
    padding: 1rem;
  }

  .topbar,
  .panel-head,
  .section-title-row,
  .list-summary,
  .modal-head,
  .negative-mix-head {
    display: grid;
    grid-template-columns: 1fr;
    align-items: start;
  }

  .topbar-actions {
    width: 100%;
  }

  .topbar-actions button {
    width: 100%;
  }

  .sidebar-tabs {
    display: grid;
  }

  .playfield {
    min-height: 540px;
  }
}
