:root {
  --bg: #0f1218;
  --surface: #171c26;
  --surface2: #1e2533;
  --border: #2a3345;
  --text: #e8ecf4;
  --muted: #8b95a8;
  --accent: #5ee1d6;
  --accent2: #c77dff;
  --danger: #ff6b8a;
  --win: #6ee7a0;
  --radius: 12px;
  --font: "Segoe UI", "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  background: radial-gradient(1200px 800px at 10% -10%, #1a2233 0%, var(--bg) 55%);
  color: var(--text);
  line-height: 1.5;
}

.app-header {
  padding: 1.25rem 1.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.app-header h1 {
  margin: 0 0 0.2rem;
  font-size: 1.35rem;
}

.app-header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.layout {
  display: grid;
  grid-template-columns: 200px 1fr;
  min-height: calc(100vh - 80px);
}

@media (max-width: 800px) {
  .layout {
    grid-template-columns: 1fr;
  }
  nav.side {
    flex-direction: row;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}

nav.side {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 1rem;
  border-right: 1px solid var(--border);
  background: var(--surface);
}

nav.side button {
  text-align: left;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
}

nav.side button.active {
  border-color: var(--accent);
  background: rgba(94, 225, 214, 0.12);
}

.nick-row {
  margin-top: auto;
  padding-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.main {
  padding: 1rem 1.25rem 2rem;
}

.panel-section {
  display: none;
}

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.stat-pill {
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: var(--surface2);
  border: 1px solid var(--border);
  font-size: 0.85rem;
}

.stat-pill strong {
  color: var(--accent);
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
}

.btn {
  padding: 0.55rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  font-size: 0.95rem;
}

.btn.primary {
  background: linear-gradient(135deg, rgba(94, 225, 214, 0.25), rgba(199, 125, 255, 0.2));
  border-color: var(--accent);
}

.btn.ghost {
  background: transparent;
}

.btn-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 0.75rem 0;
}

.input,
.select-input {
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.95rem;
}

.mono {
  font-family: ui-monospace, Consolas, monospace;
  letter-spacing: 0.08em;
}

.gacha-stage {
  min-height: 120px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  background: var(--surface2);
}

.gacha-stage.revealed .gacha-text {
  color: var(--accent);
  font-size: 2rem;
  font-weight: 700;
  animation: pop 0.35s ease;
}

@keyframes pop {
  from {
    transform: scale(0.8);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.log-list {
  max-height: 200px;
  overflow: auto;
  padding-left: 1.2rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.word-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.word-chip {
  padding: 0.45rem 0.35rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  font-size: 0.8rem;
  cursor: pointer;
}

.word-chip.mystery {
  color: var(--muted);
  cursor: default;
}

.word-chip.owned {
  border-color: rgba(94, 225, 214, 0.4);
  color: #fff;
  cursor: default;
}

.combine-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
}

.combine-slots {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.combine-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.combine-row label {
  width: 1.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.combine-row select {
  flex: 1;
  min-width: 160px;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: #fff;
}

.combine-preview-label {
  margin: 0 0 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.combine-preview {
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  background: var(--surface2);
  border: 1px solid var(--border);
  font-size: 1.1rem;
  color: #fff;
}

.combine-status.error {
  color: var(--danger);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 0.5rem;
}

.card-tile {
  padding: 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: linear-gradient(145deg, var(--surface2), #252d3d);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-height: 4.5rem;
}

.card-text-fit {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  line-clamp: 4;
  overflow: hidden;
  word-break: break-all;
  line-height: 1.25;
  color: #fff;
}

.card-power {
  font-size: 0.8rem;
  color: var(--accent);
  flex-shrink: 0;
}

.deck-screen {
  display: none;
}

.deck-screen.active {
  display: block;
}

.deck-picker-list {
  list-style: none;
  padding: 0;
  margin: 0 0 1.25rem;
}

.deck-picker-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  margin-bottom: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface2);
  cursor: pointer;
  transition: border-color 0.15s;
}

.deck-picker-item:hover {
  border-color: var(--accent);
}

.deck-picker-item.incomplete {
  opacity: 0.85;
}

.deck-picker-name {
  font-weight: 600;
  color: #fff;
}

.deck-picker-meta {
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
}

.deck-picker-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
}

.btn.xl {
  width: 100%;
  padding: 0.85rem 1rem;
  font-size: 1rem;
}

.deck-edit-header {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin: 1rem 0 0.5rem;
}

.deck-edit-header label {
  font-size: 0.9rem;
  color: var(--muted);
}

.deck-edit-header .input {
  flex: 1;
  min-width: 180px;
}

.deck-status {
  margin: 0.5rem 0 1rem;
  font-size: 0.95rem;
}

.deck-status.ok {
  color: var(--win);
}

.hint-inline {
  font-size: 0.8rem;
  font-weight: normal;
  color: var(--muted);
}

.deck-edit-actions {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.deck-slots {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.deck-slot {
  min-height: 52px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.deck-slot.filled {
  border-style: solid;
  border-color: var(--accent);
}

.deck-slot-label {
  width: 100%;
  -webkit-line-clamp: 3;
  line-clamp: 3;
}

.deck-pool {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.pool-card {
  padding: 0.35rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.8rem;
  cursor: pointer;
  max-width: 160px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
}

.pool-card-label {
  width: 100%;
  -webkit-line-clamp: 3;
  line-clamp: 3;
}

.pool-card small {
  color: var(--muted);
  font-size: 0.7rem;
}

#deck-status.ok {
  color: var(--win);
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.join-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.room-code-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.75rem 0;
}

.lobby-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
}

.lobby-player {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.35rem;
  background: var(--surface2);
}

.lobby-player.ready {
  border-color: var(--win);
}

.lobby-deck-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.75rem;
}

.turn-banner {
  font-weight: 600;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  background: var(--surface2);
  margin-bottom: 1rem;
}

.turn-banner.your-turn {
  border: 1px solid var(--accent);
  color: var(--accent);
}

.battle-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 700px) {
  .battle-layout {
    grid-template-columns: 1fr;
  }
}

.battle-field {
  min-height: 100px;
  padding: 1rem;
  border: 2px solid var(--accent2);
  border-radius: var(--radius);
  background: var(--surface2);
}

.field-card {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field-holder {
  font-size: 0.8rem;
  color: var(--muted);
}

.field-text {
  font-weight: 700;
  color: #fff;
  word-break: break-all;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  line-clamp: 4;
  overflow: hidden;
}

.bp-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.25rem 0.5rem;
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  margin-bottom: 0.3rem;
  background: var(--surface2);
  font-size: 0.85rem;
}

.bp-row.you {
  border: 1px solid rgba(94, 225, 214, 0.35);
}

.bp-row.out {
  opacity: 0.45;
}

.bp-tags {
  grid-column: 1 / -1;
  color: var(--accent);
  font-size: 0.75rem;
}

.battle-hand {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  min-height: 80px;
}

.hand-card {
  min-width: 88px;
  max-width: 140px;
  min-height: 4rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: linear-gradient(145deg, #283044, var(--surface2));
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  text-align: center;
}

.hand-card .card-text-fit {
  flex: 1;
  -webkit-line-clamp: 4;
  line-clamp: 4;
}

.hand-card small {
  flex-shrink: 0;
  color: var(--accent);
}

.hand-card:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.battle-log {
  max-height: 160px;
}

.result-text {
  font-size: 2rem;
  font-weight: 700;
  text-align: center;
  margin: 2rem 0;
}

.result-text.win {
  color: var(--win);
}

.result-text.lose {
  color: var(--danger);
}

.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.65rem 1.25rem;
  background: #252d3d;
  border: 1px solid var(--border);
  border-radius: 999px;
  z-index: 999;
  font-size: 0.9rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  color: var(--muted);
}
