/* ==========================================================================
   正負湊十 — 溫潤紙感簡約風 (Warm Paper Minimalism)
   ========================================================================== */

:root {
  /* Paper Neutrals */
  --bg-canvas: #FAFAF8;
  --bg-surface: #FFFFFF;
  --bg-subtle: #F3F2EE;
  --bg-hover: #EAE8E1;

  --border-subtle: #E7E5DF;
  --border-strong: #D5D1C8;

  --text-primary: #1C1917;
  --text-secondary: #57534E;
  --text-muted: #8C867E;

  /* Semantic Positive (Calm Indigo / Slate Blue) */
  --pos-bg: #F3F7FC;
  --pos-bg-hover: #E9F1FA;
  --pos-border: #2D5182;
  --pos-text: #1E3B63;
  --pos-soft: #DCE8F7;
  --pos-handle: #8AA5C8;

  /* Semantic Negative (Crisp Coral / Vermilion Red) */
  --neg-bg: #FDF3F2;
  --neg-bg-hover: #FCE8E6;
  --neg-border: #C83E37;
  --neg-text: #9E2620;
  --neg-soft: #FADDD9;
  --neg-handle: #DE8E8A;

  /* Zero / Neutral */
  --zero-bg: #F5F5F4;
  --zero-border: #9E9890;
  --zero-text: #57534E;

  /* Success */
  --ok-text: #1F6F50;
  --ok-bg: #EEF7F3;
  --ok-border: #B7DFCE;

  /* Typography */
  --font-sans: 'Plus Jakarta Sans', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Radii & Motion */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --shadow-paper: 0 2px 0 rgba(28, 25, 23, 0.08);
  --shadow-lift: 0 12px 28px rgba(28, 25, 23, 0.14), 0 2px 0 rgba(28, 25, 23, 0.08);
  --shadow-popover: 0 10px 30px rgba(28, 25, 23, 0.10), 0 1px 3px rgba(28, 25, 23, 0.06);
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

button, input {
  font-family: inherit;
  color: inherit;
}

button:focus-visible, input:focus-visible {
  outline: 2px solid var(--pos-border);
  outline-offset: 2px;
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   App Shell Layout
   ========================================================================== */

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
}

/* Top Bar */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 30;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 34px;
  height: 34px;
  border: 1.5px solid var(--border-strong);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-canvas);
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 14px;
}

.mark-pos {
  display: grid;
  place-items: center;
  background: var(--pos-bg);
  color: var(--pos-text);
  border-right: 1px solid var(--border-subtle);
}

.mark-neg {
  display: grid;
  place-items: center;
  background: var(--neg-bg);
  color: var(--neg-text);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-text h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

/* Mode Tabs */
.mode-tabs {
  display: inline-flex;
  background: var(--bg-subtle);
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  gap: 2px;
}

.mode-tab {
  min-height: 36px;
  padding: 0 16px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 600;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.16s var(--ease-out), color 0.16s var(--ease-out);
}

.mode-tab:hover {
  color: var(--text-primary);
}

.mode-tab.is-active {
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: 0 1px 2px rgba(28, 25, 23, 0.08);
}

/* Top Tools */
.top-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  min-width: 36px;
  padding: 0 11px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s var(--ease-out);
}

.tool-btn.icon-only {
  padding: 0;
  width: 36px;
}

.tool-btn:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.tool-btn.is-on {
  background: var(--bg-subtle);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.tool-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--border-strong);
  transition: background 0.15s;
}

.tool-btn.is-on .tool-dot {
  background: var(--ok-text);
}

/* ==========================================================================
   Context Bar (Practice & Game Modes)
   ========================================================================== */

.context-bar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  padding: 9px 20px;
  z-index: 25;
  flex-shrink: 0;
}

.context-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.practice-left {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.equation-builder {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.num-input {
  width: 74px;
  height: 38px;
  padding: 0 8px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-canvas);
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  user-select: text;
  -webkit-user-select: text;
}

.num-input:focus {
  border-color: var(--pos-border);
  background: var(--bg-surface);
}

.op-toggle {
  display: inline-flex;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.op-btn {
  width: 36px;
  height: 35px;
  border: none;
  background: var(--bg-surface);
  font-family: var(--font-mono);
  font-size: 17px;
  font-weight: 700;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.14s, color 0.14s;
}

.op-btn + .op-btn {
  border-left: 1px solid var(--border-subtle);
}

.op-btn.is-active[data-op="+"] {
  background: var(--pos-bg);
  color: var(--pos-text);
}

.op-btn.is-active[data-op="-"] {
  background: var(--neg-bg);
  color: var(--neg-text);
}

.random-generator {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.random-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}

.random-chips {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.chip-btn {
  height: 32px;
  padding: 0 11px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  background: var(--bg-canvas);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.14s;
}

.chip-btn:hover {
  border-color: var(--border-strong);
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.chip-btn.is-add:hover {
  border-color: var(--pos-border);
  background: var(--pos-bg);
  color: var(--pos-text);
}

.chip-btn.is-sub:hover {
  border-color: var(--neg-border);
  background: var(--neg-bg);
  color: var(--neg-text);
}

.deal-mode-group {
  display: inline-flex;
  background: var(--bg-subtle);
  padding: 2px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.seg-btn {
  height: 32px;
  padding: 0 10px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 500;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.14s;
}

.seg-btn.is-active {
  background: var(--bg-surface);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(28, 25, 23, 0.07);
}

/* Game Levels */
.game-levels {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.level-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-canvas);
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.level-btn:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.level-btn.is-active {
  background: var(--text-primary);
  border-color: var(--text-primary);
  color: #FFFFFF;
}

.level-stars {
  font-size: 11px;
  letter-spacing: 1px;
  color: #D97706;
}

.level-btn.is-active .level-stars {
  color: #FBBF24;
}

.game-meta {
  display: flex;
  align-items: center;
  gap: 12px;
}

.game-progress {
  display: flex;
  align-items: center;
  gap: 8px;
}

.progress-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.progress-dots {
  display: flex;
  gap: 5px;
}

.progress-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1.5px solid var(--border-strong);
  background: transparent;
  transition: all 0.2s;
}

.progress-dot.is-done {
  background: var(--ok-text);
  border-color: var(--ok-text);
}

.progress-dot.is-current {
  border-color: var(--text-primary);
  transform: scale(1.15);
}

/* Buttons */
.primary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 16px;
  border: 1px solid var(--text-primary);
  border-radius: var(--radius-sm);
  background: var(--text-primary);
  color: #FFFFFF;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.12s;
}

.primary-btn:hover {
  opacity: 0.9;
}

.primary-btn:active {
  transform: translateY(1px);
}

.primary-btn.small {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

.primary-btn.full {
  width: 100%;
}

.secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.secondary-btn:hover {
  background: var(--bg-subtle);
}

/* ==========================================================================
   Main Workspace & History Drawer
   ========================================================================== */

.workspace-wrapper {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.workspace {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg-canvas);
  touch-action: none;
}

.workspace-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(circle, rgba(28, 25, 23, 0.085) 1px, transparent 1px);
  background-size: 28px 28px;
  opacity: 0.7;
}

/* Floating Equation Banner */
.equation-banner {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 14px rgba(28, 25, 23, 0.05);
  z-index: 15;
  max-width: calc(100% - 32px);
  flex-wrap: wrap;
  justify-content: center;
}

.eq-main {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.eq-convert {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--bg-subtle);
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
}

.eq-convert .neg-highlight {
  color: var(--neg-text);
  font-weight: 700;
}

.eq-convert .pos-highlight {
  color: var(--pos-text);
  font-weight: 700;
}

.eq-status {
  font-size: 12.5px;
  color: var(--text-muted);
  border-left: 1px solid var(--border-subtle);
  padding-left: 12px;
}

/* Total Readout */
.total-readout {
  position: absolute;
  top: 16px;
  left: 20px;
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  z-index: 14;
  pointer-events: none;
}

.total-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.total-value {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 700;
  min-width: 24px;
  text-align: right;
}

.total-value.is-pos { color: var(--pos-text); }
.total-value.is-neg { color: var(--neg-text); }
.total-value.is-zero { color: var(--zero-text); }

/* Workspace Quick Actions */
.workspace-actions {
  position: absolute;
  top: 16px;
  right: 20px;
  display: flex;
  gap: 8px;
  z-index: 14;
}

.action-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.94);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.14s;
}

.action-pill:hover:not(:disabled) {
  background: var(--bg-subtle);
  border-color: var(--border-strong);
}

.action-pill:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

/* Empty State Hint */
.empty-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  max-width: 420px;
  padding: 24px;
  z-index: 5;
}

.hint-title {
  margin: 0 0 8px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
}

.hint-desc {
  margin: 0 0 18px;
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--text-secondary);
}

/* ==========================================================================
   Number Paper Cards
   ========================================================================== */

.card-layer {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

.num-card {
  position: absolute;
  left: 0;
  top: 0;
  height: 84px;
  min-width: 84px;
  border-radius: var(--radius-md);
  border: 1.75px solid var(--pos-border);
  background: var(--pos-bg);
  color: var(--pos-text);
  box-shadow: var(--shadow-paper);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: grab;
  pointer-events: auto;
  touch-action: none;
  transition:
    box-shadow 0.16s var(--ease-out),
    border-color 0.16s var(--ease-out),
    background 0.16s var(--ease-out);
  will-change: transform;
}

.num-card.is-smooth {
  transition:
    transform 0.24s var(--ease-out),
    box-shadow 0.16s var(--ease-out),
    opacity 0.24s var(--ease-out);
}

.num-card.size-one { width: 84px; }
.num-card.size-ten { width: 106px; }
.num-card.size-hundred { width: 132px; }

.num-card.is-pos {
  background: var(--pos-bg);
  border-color: var(--pos-border);
  color: var(--pos-text);
}

.num-card.is-neg {
  background: var(--neg-bg);
  border-color: var(--neg-border);
  color: var(--neg-text);
}

.num-card.is-zero {
  background: var(--zero-bg);
  border-color: var(--zero-border);
  color: var(--zero-text);
}

.num-card:hover {
  transform-origin: center;
}

.num-card.is-pos:hover { background: var(--pos-bg-hover); }
.num-card.is-neg:hover { background: var(--neg-bg-hover); }

.num-card.is-selected {
  box-shadow: 0 0 0 3px rgba(45, 81, 130, 0.22), var(--shadow-paper);
}

.num-card.is-neg.is-selected {
  box-shadow: 0 0 0 3px rgba(200, 62, 55, 0.22), var(--shadow-paper);
}

.num-card.is-dragging {
  cursor: grabbing;
  box-shadow: var(--shadow-lift);
  z-index: 1000 !important;
}

.num-card.is-drop-target {
  box-shadow: 0 0 0 3px rgba(28, 25, 23, 0.18), 0 0 0 6px rgba(28, 25, 23, 0.06);
  border-style: dashed;
}

.num-card.is-drop-blocked {
  border-color: var(--neg-border);
  border-style: dashed;
  box-shadow: 0 0 0 3px rgba(200, 62, 55, 0.22), 0 0 0 6px rgba(200, 62, 55, 0.08);
}

.num-card.is-reject-shake {
  animation: cardRejectShake 0.36s var(--ease-out);
}

.num-card.is-merge-pop {
  animation: cardPop 0.28s var(--ease-out);
}

.num-card.is-canceling {
  animation: cardCancel 0.62s var(--ease-out) forwards;
}

.num-card.is-answer-win {
  border-color: var(--ok-text);
  box-shadow: 0 0 0 4px rgba(31, 111, 80, 0.2), var(--shadow-paper);
}

/* Subtle Top Peel Handle (PhET-inspired) */
.card-peel-zone {
  position: absolute;
  top: 0;
  left: 6px;
  right: 6px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: ns-resize;
  z-index: 3;
}

.card-peel-bar {
  width: 28px;
  height: 3.5px;
  border-radius: var(--radius-pill);
  background: var(--pos-handle);
  opacity: 0.55;
  transition: opacity 0.15s, width 0.15s;
}

.num-card.is-neg .card-peel-bar {
  background: var(--neg-handle);
}

.card-peel-zone:hover .card-peel-bar {
  opacity: 1;
  width: 36px;
}

.card-peel-tip {
  position: absolute;
  top: -24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--text-primary);
  color: #FFFFFF;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.14s;
}

.card-peel-zone:hover .card-peel-tip {
  opacity: 1;
}

/* Card Main Numeral */
.card-value {
  font-family: var(--font-mono);
  font-size: 32px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
  pointer-events: none;
  margin-top: 4px;
}

.num-card.size-hundred .card-value {
  font-size: 28px;
}

/* Subtle Place-Value Sign Tag */
.card-tag {
  position: absolute;
  bottom: 5px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  opacity: 0.58;
  pointer-events: none;
}

@keyframes cardPop {
  0% { filter: brightness(1.06); }
  45% { filter: brightness(1.02); }
  100% { filter: brightness(1); }
}

@keyframes cardCancel {
  0% { opacity: 1; }
  35% { opacity: 0.85; }
  100% { opacity: 0; filter: blur(2px); }
}

@keyframes cardRejectShake {
  0%, 100% { left: 0; }
  20% { left: -6px; }
  45% { left: 6px; }
  70% { left: -4px; }
  88% { left: 3px; }
}

/* ==========================================================================
   FX Layer (Equation Bubbles & Cancellation Ripples)
   ========================================================================== */

.fx-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 40;
}

.eq-bubble {
  position: absolute;
  transform: translate(-50%, -100%);
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: var(--text-primary);
  color: #FFFFFF;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 6px 18px rgba(28, 25, 23, 0.16);
  animation: bubbleFloat 1.55s var(--ease-out) forwards;
}

.eq-bubble.is-cancel {
  background: #44403C;
}

.eq-bubble.is-make-ten {
  background: var(--ok-text);
}

.eq-bubble.is-blocked {
  background: var(--neg-text);
  font-family: var(--font-sans);
  font-size: 12.5px;
  animation-duration: 2.05s;
}

@keyframes bubbleFloat {
  0% { opacity: 0; transform: translate(-50%, -65%) scale(0.92); }
  16% { opacity: 1; transform: translate(-50%, -115%) scale(1); }
  78% { opacity: 1; transform: translate(-50%, -132%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -155%) scale(0.96); }
}

.cancel-ripple {
  position: absolute;
  width: 96px;
  height: 96px;
  margin-left: -48px;
  margin-top: -48px;
  border-radius: 50%;
  border: 2px solid var(--zero-border);
  animation: rippleOut 0.65s var(--ease-out) forwards;
}

@keyframes rippleOut {
  0% { transform: scale(0.45); opacity: 0.8; }
  100% { transform: scale(1.65); opacity: 0; }
}

/* Merge Preview Pill (while hovering another card) */
.merge-preview {
  position: absolute;
  z-index: 1050;
  transform: translate(-50%, -100%);
  padding: 5px 11px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  border: 1.5px solid var(--text-primary);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 6px 16px rgba(28, 25, 23, 0.12);
}

.merge-preview.is-make-ten {
  background: var(--ok-bg);
  border-color: var(--ok-text);
  color: var(--ok-text);
}

.merge-preview.is-blocked {
  background: var(--neg-bg);
  border-color: var(--neg-border);
  color: var(--neg-text);
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 600;
}

/* ==========================================================================
   Split Popover
   ========================================================================== */

.split-popover {
  position: absolute;
  z-index: 60;
  width: 268px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-popover);
  padding: 14px;
}

.split-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.split-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.popover-close {
  width: 30px;
  height: 30px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 20px;
  line-height: 1;
  border-radius: 6px;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.popover-close:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.split-section + .split-section {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
}

.split-place-btn {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-canvas);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: all 0.14s;
}

.split-place-btn:hover {
  border-color: var(--text-primary);
  background: var(--bg-subtle);
}

.split-btn-label {
  font-size: 13px;
  font-weight: 600;
}

.split-btn-preview {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--pos-text);
}

.split-popover.is-neg .split-btn-preview {
  color: var(--neg-text);
}

.split-custom-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.split-sublabel {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.split-preview-mono {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.split-slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.step-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-canvas);
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.step-btn:hover {
  background: var(--bg-subtle);
}

#splitSlider {
  flex: 1;
  accent-color: var(--pos-border);
  cursor: pointer;
  height: 24px;
}

.split-popover.is-neg #splitSlider {
  accent-color: var(--neg-border);
}

.split-quick-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 10px;
}

.quick-split-pill {
  height: 28px;
  padding: 0 9px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  background: var(--bg-canvas);
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}

.quick-split-pill:hover {
  border-color: var(--text-primary);
  color: var(--text-primary);
}

.split-footer {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
  text-align: center;
}

.danger-text-btn {
  border: none;
  background: transparent;
  color: var(--neg-text);
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.danger-text-btn:hover {
  background: var(--neg-bg);
}

/* ==========================================================================
   Clear / Success Overlay
   ========================================================================== */

.clear-overlay {
  position: absolute;
  inset: 0;
  background: rgba(250, 250, 248, 0.72);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  z-index: 70;
  padding: 20px;
}

.clear-card {
  width: min(420px, 100%);
  background: var(--bg-surface);
  border: 1.5px solid var(--ok-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  text-align: center;
  box-shadow: var(--shadow-popover);
}

.clear-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  background: var(--ok-bg);
  color: var(--ok-text);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 10px;
}

.clear-eq {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.clear-steps-wrap {
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px;
  margin-bottom: 18px;
  text-align: left;
}

.clear-steps-label {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.clear-steps {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-primary);
}

.clear-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ==========================================================================
   History Drawer
   ========================================================================== */

.history-drawer {
  width: 280px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  padding: 16px;
  z-index: 20;
  flex-shrink: 0;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.drawer-header h2 {
  margin: 0;
  font-size: 14.5px;
  font-weight: 700;
}

.drawer-caption {
  margin: 0 0 14px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
}

.history-list {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 11px;
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
}

.history-tag {
  font-family: var(--font-sans);
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}

.history-tag.is-merge {
  background: var(--pos-bg);
  color: var(--pos-text);
}

.history-tag.is-cancel {
  background: var(--neg-bg);
  color: var(--neg-text);
}

.history-tag.is-split {
  background: var(--bg-subtle);
  color: var(--text-secondary);
}

.history-empty {
  font-size: 12.5px;
  color: var(--text-muted);
  text-align: center;
  padding: 24px 8px;
}

/* ==========================================================================
   Bottom Card Tray
   ========================================================================== */

.tray-bar {
  position: relative;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  padding: 12px 20px;
  z-index: 25;
  flex-shrink: 0;
}

.tray-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  max-width: 980px;
  margin: 0 auto;
}

.tray-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.tray-group-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.tray-group-label.is-pos { color: var(--pos-text); }
.tray-group-label.is-neg { color: var(--neg-text); }

.tray-cards {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tray-card {
  height: 52px;
  min-width: 56px;
  padding: 0 12px;
  border-radius: 9px;
  border: 1.75px solid;
  font-family: var(--font-mono);
  font-size: 19px;
  font-weight: 700;
  cursor: grab;
  touch-action: none;
  box-shadow: var(--shadow-paper);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.14s var(--ease-out), background 0.14s;
}

.tray-card.is-ten { min-width: 68px; }
.tray-card.is-hundred { min-width: 82px; }

.tray-card.is-pos {
  background: var(--pos-bg);
  border-color: var(--pos-border);
  color: var(--pos-text);
}

.tray-card.is-pos:hover {
  background: var(--pos-bg-hover);
  transform: translateY(-2px);
}

.tray-card.is-neg {
  background: var(--neg-bg);
  border-color: var(--neg-border);
  color: var(--neg-text);
}

.tray-card.is-neg:hover {
  background: var(--neg-bg-hover);
  transform: translateY(-2px);
}

.tray-center {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  border-left: 1px solid var(--border-subtle);
  border-right: 1px solid var(--border-subtle);
}

.tray-utility-btn {
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-canvas);
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.14s;
}

.tray-utility-btn:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.tray-utility-btn.is-active {
  background: var(--text-primary);
  border-color: var(--text-primary);
  color: #FFFFFF;
}

.trash-zone {
  height: 44px;
  padding: 0 12px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  transition: all 0.15s;
}

.trash-zone.is-hot {
  border-color: var(--neg-border);
  background: var(--neg-bg);
  color: var(--neg-text);
  transform: scale(1.04);
}

.tray-locked-notice {
  text-align: center;
  font-size: 13px;
  color: var(--text-secondary);
  padding: 12px 16px;
}

/* Custom Card Popover */
.custom-card-popover {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-popover);
  padding: 12px 14px;
  z-index: 65;
}

.custom-card-form label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.custom-card-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ==========================================================================
   Help Modal
   ========================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 23, 0.36);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  z-index: 200;
  padding: 20px;
}

.modal-card {
  width: min(500px, 100%);
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-popover);
  padding: 22px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-header h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

.modal-body {
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--text-secondary);
}

.help-block + .help-block {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border-subtle);
}

.help-block h3 {
  margin: 0 0 6px;
  font-size: 14px;
  color: var(--text-primary);
}

.help-block p {
  margin: 0 0 8px;
}

.help-block ul {
  margin: 0;
  padding-left: 18px;
}

.help-block li + li {
  margin-top: 4px;
}

.help-block code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.inline-pos {
  color: var(--pos-text);
  font-weight: 700;
}

.inline-neg {
  color: var(--neg-text);
  font-weight: 700;
}

.modal-footer {
  margin-top: 18px;
  display: flex;
  justify-content: flex-end;
}

/* ==========================================================================
   Responsive Polish (Tablet & Small Screens)
   ========================================================================== */

@media (max-width: 1120px) {
  .total-readout {
    top: auto;
    bottom: 12px;
    left: 12px;
  }

  .workspace-actions {
    top: auto;
    bottom: 12px;
    right: 12px;
  }
}

@media (max-width: 900px) {
  .top-bar {
    padding: 8px 12px;
    gap: 8px;
  }

  .brand-sub {
    display: none;
  }

  .mode-tab {
    padding: 0 11px;
    font-size: 13px;
  }

  .tool-btn span:not(.tool-dot) {
    display: none;
  }

  .tray-inner {
    gap: 12px;
    flex-wrap: wrap;
  }

  .tray-group-label {
    display: none;
  }

  .tray-center {
    border: none;
    padding: 0;
  }

  .history-drawer {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    box-shadow: -8px 0 24px rgba(28, 25, 23, 0.08);
  }
}
