/* ===== Reset & Base ===== */
*, *::before, *::after {
  margin: 0; padding: 0; box-sizing: border-box;
}

:root {
  --bg: #0a0a1a;
  --bg-light: #12122a;
  --gold: #c9a84c;
  --gold-dim: #8a7333;
  --gold-glow: rgba(201, 168, 76, 0.3);
  --text: #e0d5c1;
  --text-dim: #8a8070;
  --card-w: 70px;
  --card-h: 108px;
  --card-radius: 6px;
  --drawer-h: 190px;
  --topbar-h: 58px;
  --transition: 0.3s ease;
  --sand: #c3a471;
  --sand-light: #f6dfb4;
  --sand-dark: #8d6f49;
}

/* Full deck: taller drawer for 3 rows */
body.full-deck {
  --drawer-h: 260px;
}

body.full-deck.compact-full-deck {
  --drawer-h: 288px;
  --compact-full-card-w: 32px;
  --compact-full-card-h: 50px;
  --compact-full-card-step: 14px;
}

html, body {
  height: 100%; width: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', sans-serif;
  background: var(--bg);
  color: var(--text);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.hidden {
  display: none !important;
}

/* ===== Top Bar ===== */
#top-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  padding: 0 12px;
  gap: 8px;
  background: rgba(10, 10, 26, 0.92);
  border-bottom: 1px solid rgba(201, 168, 76, 0.15);
  z-index: 100;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

#mode-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  min-width: 0;
  justify-self: start;
}

#home-link {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.05);
  color: var(--text);
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.top-label {
  font-size: 10px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: rgba(224, 213, 193, 0.45);
}

#mode-label {
  margin-top: 2px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

/* Top Actions */
#top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  justify-self: end;
}

#top-actions a,
#top-actions button,
#auth-badge {
  padding: 5px 10px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.05);
  color: var(--text);
  font-size: 11px;
  text-decoration: none;
  touch-action: manipulation;
  transition: all var(--transition);
  white-space: nowrap;
}

#btn-reset,
#btn-save {
  min-height: 40px;
  padding: 8px 15px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}

#btn-save {
  justify-self: center;
  min-height: 46px;
  padding: 11px 26px;
  font-size: 15px;
  letter-spacing: 0.08em;
  border-color: rgba(201, 168, 76, 0.34);
  background: linear-gradient(135deg, rgba(201, 168, 76, 0.28), rgba(212, 182, 90, 0.18));
  color: #f5deb0;
  box-shadow: 0 8px 24px rgba(201, 168, 76, 0.18);
}

#btn-reset {
  border-color: rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.08);
  color: var(--text);
}

#btn-login {
  color: var(--gold);
}

#top-actions button:active,
#top-actions a:active {
  transform: scale(0.95);
}

/* Deck Type Tabs in Drawer */
#deck-tabs {
  display: flex;
  gap: 2px;
  background: rgba(255,255,255,0.06);
  border-radius: 8px;
  padding: 2px;
}

.deck-type-tab {
  padding: 3px 10px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.2s;
  touch-action: manipulation;
  white-space: nowrap;
}

.deck-type-tab.active {
  background: rgba(201, 168, 76, 0.2);
  color: var(--gold);
  font-weight: 600;
}

/* ===== Energy Panel ===== */
#energy-panel {
  position: fixed;
  top: var(--topbar-h);
  left: 0; right: 0;
  bottom: 0;
  z-index: 80;
  background: var(--bg);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#energy-panel.hidden { display: none; }

#energy-inner {
  max-width: 400px;
  margin: 0 auto;
  padding: 32px 20px 40px;
}

.energy-header {
  text-align: center;
  margin-bottom: 28px;
}

.energy-header .energy-icon {
  display: block;
  font-size: 32px;
  color: var(--gold);
  margin-bottom: 12px;
}

.energy-header h3 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.energy-header p {
  font-size: 13px;
  color: var(--text-dim);
}

/* Deck selector in energy panel */
.deck-select {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 24px;
  padding: 12px 16px;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04);
}

.deck-select-label {
  font-size: 13px;
  color: var(--text-dim);
}

#energy-deck-tabs {
  display: flex;
  gap: 2px;
  background: rgba(255,255,255,0.06);
  border-radius: 8px;
  padding: 2px;
}

#energy-deck-tabs .deck-type-tab {
  padding: 6px 14px;
  font-size: 13px;
}

.energy-item {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  padding: 10px 14px;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.05);
  backdrop-filter: blur(4px);
}

.energy-item input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 14px;
}

.energy-item input::placeholder {
  color: rgba(224, 213, 193, 0.35);
}

.energy-remove {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.05);
  color: var(--gold);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  touch-action: manipulation;
}

#add-energy {
  width: 100%;
  padding: 12px;
  border-radius: 16px;
  border: 1px dashed rgba(201, 168, 76, 0.4);
  background: transparent;
  color: var(--gold);
  font-size: 13px;
  cursor: pointer;
  margin-top: 4px;
  margin-bottom: 20px;
  transition: all 0.2s;
  touch-action: manipulation;
}

#add-energy:active {
  background: rgba(201, 168, 76, 0.1);
}

#start-sandbox {
  width: 100%;
  padding: 14px;
  border-radius: 20px;
  border: none;
  background: linear-gradient(135deg, var(--gold), #d4b65a);
  color: var(--bg);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  touch-action: manipulation;
}

#start-sandbox:active {
  transform: scale(0.98);
}

#start-sandbox:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ===== Arena ===== */
#arena {
  position: fixed;
  top: var(--topbar-h); left: 0; right: 0;
  bottom: var(--drawer-h);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(30, 20, 60, 0.8) 0%, transparent 70%),
    var(--bg);
  transition: background 0.5s, bottom 0.3s;
}

/* Sandbox mode arena */
#arena.sandbox-board {
  background:
    radial-gradient(circle at top, var(--sand-light) 0%, #ead09a 25%, var(--sand) 60%, var(--sand-dark) 100%);
}

#arena-content {
  position: relative;
  width: 1200px;
  height: 1200px;
  transform-origin: 0 0;
  transition: transform 0.2s ease;
}

#arena-hint {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.8;
  pointer-events: none;
  transition: opacity var(--transition);
}

#arena-hint .hint-icon {
  font-size: 40px;
  margin-bottom: 12px;
  animation: float 3s ease-in-out infinite;
}

#arena-hint.hidden { opacity: 0; }

/* Sandbox hint color override */
#arena.sandbox-board #arena-hint {
  color: rgba(93, 71, 45, 0.6);
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* ===== Arena Cards ===== */
.arena-card {
  position: absolute;
  width: var(--card-w);
  height: var(--card-h);
  cursor: grab;
  perspective: 600px;
  transition: box-shadow 0.2s;
  z-index: 1;
  animation: cardAppear 0.4s ease-out;
}

.arena-card.dragging {
  cursor: grabbing;
  z-index: 9999;
  filter: brightness(1.1);
}

.arena-card .card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.6s ease;
}

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

.arena-card .card-face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--card-radius);
  overflow: hidden;
}

.arena-card .card-back {
  z-index: 2;
}

.arena-card .card-front {
  transform: rotateY(180deg);
}

.arena-card.revealed {
  cursor: pointer;
}

@keyframes cardAppear {
  from { opacity: 0; transform: scale(0.5); }
  to { opacity: 1; transform: scale(1); }
}

/* ===== Energy Label on Cards ===== */
.energy-label {
  position: absolute;
  bottom: -28px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 10px;
  background: rgba(10, 10, 26, 0.85);
  color: var(--gold);
  border: 1px solid rgba(201, 168, 76, 0.3);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}

.sandbox-board .energy-label {
  background: rgba(93, 71, 45, 0.85);
  color: var(--sand-light);
  border-color: rgba(246, 223, 180, 0.3);
}

.arena-card.revealed .energy-label {
  opacity: 1;
}

/* ===== Energy Input (Normal Mode) ===== */
.energy-input {
  position: absolute;
  bottom: -30px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(var(--card-w) + 8px);
  padding: 3px 8px;
  border-radius: 8px;
  border: 1px solid rgba(201, 168, 76, 0.25);
  background: rgba(10, 10, 26, 0.7);
  color: var(--gold);
  font-size: 10px;
  text-align: center;
  outline: none;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: border-color 0.2s, background 0.2s;
  user-select: text;
  -webkit-user-select: text;
  touch-action: manipulation;
}

.energy-input::placeholder {
  color: rgba(201, 168, 76, 0.3);
  font-size: 10px;
}

.energy-input:focus {
  border-color: var(--gold);
  background: rgba(10, 10, 26, 0.9);
}

/* ===== Card Back Design ===== */
/* Card back uses image */
.card-back-design {
  width: 100%;
  height: 100%;
  background: url('/cards/back.webp') center/cover no-repeat;
  border: 2px solid var(--gold);
  border-radius: var(--card-radius);
  position: relative;
  overflow: hidden;
}

/* ===== Card Front Design ===== */
.card-front-design {
  width: 100%;
  height: 100%;
  background: linear-gradient(to bottom, #f5e6d3, #e8d5b7);
  border: 2px solid var(--gold);
  border-radius: var(--card-radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px;
  position: relative;
}

.card-front-design img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 4px;
  position: absolute;
  inset: 0;
  z-index: 1;
}

/* Hidden - kept for fallback only */
.card-front-design .card-number,
.card-front-design .card-symbol,
.card-front-design .card-label {
  display: none;
}

/* ===== Floating Controls ===== */
#controls {
  position: fixed;
  right: 12px;
  bottom: calc(var(--drawer-h) + 16px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
}

#controls button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1.5px solid var(--gold-dim);
  background: rgba(10, 10, 26, 0.85);
  color: var(--gold);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: all var(--transition);
  touch-action: manipulation;
}

#controls button:active {
  transform: scale(0.9);
  background: rgba(201, 168, 76, 0.2);
}

/* Reveal button - text, prominent */
#btn-reveal {
  width: auto;
  height: auto;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 2px;
  border-color: var(--gold);
  background: linear-gradient(135deg, rgba(201, 168, 76, 0.25), rgba(201, 168, 76, 0.1));
  box-shadow: 0 0 20px var(--gold-glow), 0 2px 8px rgba(0,0,0,0.3);
}

#btn-reveal:active {
  transform: scale(0.95);
  background: linear-gradient(135deg, rgba(201, 168, 76, 0.4), rgba(201, 168, 76, 0.2));
}

/* ===== Drawer ===== */
#drawer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--drawer-h);
  background: var(--bg-light);
  border-top: 1px solid rgba(201, 168, 76, 0.2);
  z-index: 50;
  transition: transform var(--transition), height var(--transition);
  display: flex;
  flex-direction: column;
}

#drawer.collapsed {
  transform: translateY(calc(var(--drawer-h) - 40px));
}

#drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  cursor: pointer;
  flex-shrink: 0;
  min-height: 40px;
  touch-action: manipulation;
}

.drawer-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--gold);
}

#drawer-count {
  font-size: 12px;
  color: var(--text-dim);
}

#drawer-toggle {
  color: var(--gold-dim);
  font-size: 16px;
  transition: transform var(--transition);
}

#drawer.collapsed #drawer-toggle {
  transform: rotate(180deg);
}

#drawer-body {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 8px 8px;
}

/* ===== Drawer Cards - Row Layout ===== */
#drawer-cards {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: max-content;
  min-width: 100%;
}

body.full-deck.compact-full-deck #drawer-body {
  overflow-x: hidden;
  padding: 0 4px 8px;
}

body.full-deck.compact-full-deck #drawer-cards {
  gap: 2px;
  width: 100%;
  min-width: 0;
}

#drawer-cards::-webkit-scrollbar {
  height: 3px;
}

#drawer-cards::-webkit-scrollbar-track {
  background: transparent;
}

#drawer-cards::-webkit-scrollbar-thumb {
  background: var(--gold-dim);
  border-radius: 2px;
}

/* Deck Row */
.deck-row {
  display: flex;
  gap: 4px;
  padding: 2px 4px;
  flex-shrink: 0;
  align-items: center;
}

body.full-deck.compact-full-deck .deck-row {
  width: 100%;
  justify-content: flex-start;
  padding: 1px 2px;
}

/* Cascade mode: overlapping cards */
.deck-row.cascade {
  gap: 0;
}

.deck-row.cascade .deck-card {
  margin-left: -14px;
  transition: all 0.2s ease;
}

.deck-row.cascade .deck-card:first-child {
  margin-left: 0;
}

body.full-deck.compact-full-deck .deck-row.cascade .deck-card {
  margin-left: calc(var(--row-card-step, var(--compact-full-card-step)) - var(--compact-full-card-w));
  transition: opacity 0.2s ease, box-shadow 0.2s ease;
}

/* Hover/touch: card rises up */
.deck-row.cascade .deck-card:hover,
.deck-row.cascade .deck-card:active {
  transform: translateY(-8px) scale(1.05);
  z-index: 10;
  box-shadow: 0 4px 12px rgba(201, 168, 76, 0.3);
}

body.full-deck.compact-full-deck .deck-row.cascade .deck-card:hover,
body.full-deck.compact-full-deck .deck-row.cascade .deck-card:active,
body.full-deck.compact-full-deck .deck-card:active {
  transform: none;
  box-shadow: none;
}

/* ===== Drawer Cards ===== */
.deck-card {
  flex-shrink: 0;
  width: 46px;
  height: 71px;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s ease;
  touch-action: manipulation;
  position: relative;
}

body.full-deck.compact-full-deck .deck-card {
  width: var(--compact-full-card-w);
  height: var(--compact-full-card-h);
  border-radius: 3px;
}

.deck-card:active {
  transform: scale(0.92);
}

.deck-card .card-back-design {
  border-radius: 4px;
}

body.full-deck.compact-full-deck .deck-card .card-back-design {
  border-radius: 3px;
}

.deck-card.selected {
  opacity: 0.3;
  pointer-events: none;
  transform: scale(0.9);
}

/* ===== Sandbox energy remaining hint ===== */
#sandbox-hint {
  position: fixed;
  top: calc(var(--topbar-h) + 8px);
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: rgba(93, 71, 45, 0.7);
  background: rgba(246, 223, 180, 0.8);
  padding: 4px 14px;
  border-radius: 12px;
  z-index: 90;
  pointer-events: none;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: opacity 0.3s;
}

#sandbox-hint.hidden { opacity: 0; pointer-events: none; }

/* ===== Modal ===== */
#modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

#modal.hidden {
  display: none;
}

#modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

#modal-content {
  position: relative;
  z-index: 1;
  animation: modalIn 0.3s ease;
  width: 100vw;
  height: 100vh;
  padding: 14px 14px 22px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: space-between;
  box-sizing: border-box;
}

#modal-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

#modal-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

#modal-card-wrap {
  height: min(82vh, calc(100vh - 180px));
  max-width: calc(100vw - 28px);
  aspect-ratio: 0.68 / 1;
  border-radius: 18px;
  overflow: hidden;
  border: 2px solid var(--gold);
  box-shadow: 0 0 40px var(--gold-glow);
  background: rgba(10, 10, 26, 0.94);
}

#modal-img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: rgba(10, 10, 26, 0.94);
}

#modal-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(to bottom, #f5e6d3, #e8d5b7);
}

#modal-placeholder.hidden { display: none; }

#modal-placeholder .card-symbol { font-size: 60px; margin-bottom: 12px; }
#modal-placeholder .card-label { font-size: 18px; color: #4a3a2a; font-weight: 600; }
#modal-placeholder .card-number { font-size: 14px; color: var(--gold-dim); margin-top: 8px; }

#modal-meta {
  text-align: center;
}

#modal-name {
  margin-top: 10px;
  font-size: 18px;
  color: var(--gold);
  font-weight: 600;
}

#modal-energy {
  margin-top: 10px;
  font-size: 14px;
  color: var(--sand-light);
  padding: 6px 16px;
  border-radius: 12px;
  background: rgba(141, 111, 73, 0.6);
  display: inline-block;
}

#modal-energy.hidden { display: none; }

#modal-close {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--gold-dim);
  background: rgba(10, 10, 26, 0.8);
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1); }
}

/* ===== Confirm Dialog ===== */
#confirm-dialog {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}

#confirm-dialog.hidden { display: none; }

#confirm-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
}

#confirm-box {
  position: relative;
  z-index: 1;
  background: var(--bg-light);
  border: 1px solid var(--gold-dim);
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  max-width: 280px;
  animation: modalIn 0.2s ease;
}

#confirm-box p {
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 20px;
  color: var(--text);
}

.confirm-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.confirm-buttons button {
  padding: 8px 24px;
  border-radius: 8px;
  border: 1px solid var(--gold-dim);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

#confirm-yes {
  background: var(--gold);
  color: var(--bg);
  border-color: var(--gold);
  font-weight: 600;
}

#confirm-no {
  background: transparent;
  color: var(--text);
}

/* ===== Save Dialog ===== */
#save-dialog {
  position: fixed;
  inset: 0;
  z-index: 2100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

#save-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.74);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

#save-box {
  position: relative;
  z-index: 1;
  width: min(100%, 360px);
  border-radius: 18px;
  border: 1px solid rgba(201, 168, 76, 0.24);
  background: linear-gradient(180deg, rgba(18, 18, 42, 0.96), rgba(10, 10, 26, 0.96));
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  padding: 20px;
  animation: modalIn 0.2s ease;
}

#save-box h3 {
  font-size: 18px;
  color: var(--text);
}

.save-tip {
  margin-top: 12px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--gold);
}

.save-section-title {
  margin-top: 16px;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(224, 213, 193, 0.4);
}

#save-title,
#save-note {
  width: 100%;
  margin-top: 14px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  padding: 12px 14px;
  outline: none;
  font-size: 14px;
}

#save-note {
  resize: none;
  line-height: 1.6;
}

#save-title::placeholder,
#save-note::placeholder {
  color: rgba(224, 213, 193, 0.32);
}

#save-folder-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.save-folder-tab {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.05);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}

.save-folder-tab.active {
  border-color: rgba(201, 168, 76, 0.32);
  background: rgba(201, 168, 76, 0.14);
  color: var(--gold);
}

.save-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.save-row input {
  min-width: 0;
}

.save-buttons {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
}

.save-buttons button {
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.05);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

#save-confirm {
  border-color: rgba(201, 168, 76, 0.4);
  background: linear-gradient(135deg, rgba(201, 168, 76, 0.22), rgba(201, 168, 76, 0.14));
  color: var(--gold);
  font-weight: 600;
}

/* ===== Toast ===== */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--drawer-h) + 28px);
  transform: translateX(-50%);
  z-index: 2200;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(10, 10, 26, 0.92);
  color: var(--text);
  font-size: 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.24);
}

/* ===== Responsive ===== */
@media (max-width: 400px) {
  :root {
    --card-w: 60px;
    --card-h: 92px;
    --topbar-h: 56px;
  }
  .deck-card {
    width: 42px;
    height: 65px;
  }
  /* Tighter overlap on small screens */
  .deck-row.cascade .deck-card {
    margin-left: -16px;
  }
  body.full-deck {
    --drawer-h: 240px;
  }
  body.full-deck.compact-full-deck {
    --drawer-h: 268px;
    --compact-full-card-w: 30px;
    --compact-full-card-h: 46px;
    --compact-full-card-step: 13px;
  }
  #home-link {
    width: 30px;
    height: 30px;
  }
  #mode-label {
    font-size: 12px;
  }
  #top-actions {
    gap: 4px;
  }
  #top-actions a,
  #top-actions button,
  #auth-badge {
    padding: 5px 8px;
    font-size: 10px;
  }
  #btn-reset,
  #btn-save {
    min-height: 36px;
    padding: 7px 12px;
    font-size: 12px;
  }
  #btn-save {
    min-height: 40px;
    padding: 9px 18px;
    font-size: 13px;
  }
}

@media (min-width: 768px) {
  :root {
    --card-w: 90px;
    --card-h: 138px;
    --drawer-h: 230px;
  }
  body.full-deck {
    --drawer-h: 310px;
  }
  .deck-card {
    width: 56px;
    height: 86px;
  }
  .deck-row.cascade .deck-card {
    margin-left: -20px;
  }
  #modal-content {
    padding: 18px 22px 28px;
  }
  #modal-card-wrap {
    height: min(86vh, calc(100vh - 190px));
    max-width: min(640px, calc(100vw - 44px));
  }
  #modal-name {
    font-size: 20px;
  }
  #modal-energy {
    font-size: 15px;
  }
}
