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

:root {
  --blue: #1a6aff;
  --red: #ef2d2d;
  --gray-bg: #f0f0f0;
  --gray-border: #c0c0c0;
  --gray-dark: #888;
  --slot-empty: #f5f5f5;
  --slot-border: #d0d0d0;
  --chip-size: 48px;
  --chip-size-toolbar: 32px;
  --ship-gap: 16px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #fafafa;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  padding: 24px 12px;
  -webkit-user-select: none;
  user-select: none;
}

.app {
  width: 100%;
  max-width: 760px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

/* ===== Toolbar ===== */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--gray-bg);
  border: 1px solid var(--gray-border);
  border-radius: 14px;
  padding: 8px 14px;
  justify-content: center;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.toolbar-divider {
  width: 1px;
  height: calc(var(--chip-size) + 8px);
  background: var(--gray-border);
  margin: 0 4px;
  flex-shrink: 0;
}

.tool-btn {
  background: #fff;
  border: 1px solid var(--gray-border);
  border-radius: 10px;
  padding: 6px 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: calc(var(--chip-size) + 16px);
  min-height: calc(var(--chip-size) + 12px);
  transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
  position: relative;
  flex-shrink: 0;
}

.tool-btn:hover {
  background: #f0f4ff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.10);
}

.tool-btn:active {
  transform: scale(0.95);
}

.tool-btn:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

/* ===== Chip (circle token) — 3D raised look ===== */
.chip {
  width: var(--chip-size);
  height: var(--chip-size);
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.chip--blue {
  background: radial-gradient(ellipse 60% 50% at 35% 30%, rgba(255,255,255,0.35) 0%, transparent 70%), var(--blue);
  box-shadow:
    0 2px 5px rgba(26, 106, 255, 0.35),
    inset 0 1px 2px rgba(255,255,255,0.25);
}

.chip--red {
  background: radial-gradient(ellipse 60% 50% at 35% 30%, rgba(255,255,255,0.35) 0%, transparent 70%), var(--red);
  box-shadow:
    0 2px 5px rgba(239, 45, 45, 0.35),
    inset 0 1px 2px rgba(255,255,255,0.25);
}

.chip--ghost {
  position: relative;
  opacity: 0.35;
  box-shadow: none;
  background: var(--blue); /* reset ghost to flat */
}

.chip--ghost.chip--red {
  background: var(--red);
}

.chip--ghost .chip-x {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: calc(var(--chip-size) * 0.5);
  font-weight: 700;
  line-height: 1;
}

/* Chip stack (5er) — overlapping, based on --chip-size */
.chip-stack {
  width: var(--chip-size);
  height: var(--chip-size);
  position: relative;
  flex-shrink: 0;
}

.chip--mini {
  /* ~58% of chip-size */
  width: calc(var(--chip-size) * 0.58);
  height: calc(var(--chip-size) * 0.58);
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  border: 1.5px solid rgba(255,255,255,0.6);
}

/* Overlapping horizontal row — offsets scale with chip-size */
.chip--mini:nth-child(1) { left: 0;                              z-index: 5; }
.chip--mini:nth-child(2) { left: calc(var(--chip-size) * 0.12);  z-index: 4; }
.chip--mini:nth-child(3) { left: calc(var(--chip-size) * 0.24);  z-index: 3; }
.chip--mini:nth-child(4) { left: calc(var(--chip-size) * 0.36);  z-index: 2; }
.chip--mini:nth-child(5) { left: calc(var(--chip-size) * 0.48);  z-index: 1; }

.chip-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--gray-dark);
  margin-left: 4px;
}

/* Broom */
.broom-icon {
  width: 28px;
  height: 28px;
}

/* ===== Ship Area — Two separate halves ===== */
.ship-area {
  width: 100%;
  display: flex;
  justify-content: center;
  position: relative;
}

.ship {
  display: flex;
  align-items: center;
  gap: var(--ship-gap);
}

.ship-half {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 20px;
  background: #e8e8e8;
  border: 2px solid #b8b8b8;
  border-radius: 50px;
  position: relative;
}

/* Subtle inner highlight along the top */
.ship-half::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 20px;
  right: 20px;
  height: 2px;
  background: rgba(255,255,255,0.5);
  border-radius: 1px;
}

.slot {
  width: var(--chip-size);
  height: var(--chip-size);
  position: relative;
}

.slot-circle {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--slot-empty);
  border: 2px solid var(--slot-border);
  transition: background 0.25s, border-color 0.25s, box-shadow 0.25s;
}

/* ===== Ship chips — 3D raised look ===== */
.slot.filled-blue .slot-circle {
  background: radial-gradient(ellipse 60% 50% at 35% 30%, rgba(255,255,255,0.35) 0%, transparent 70%), var(--blue);
  border-color: var(--blue);
  box-shadow:
    0 3px 6px rgba(26, 106, 255, 0.35),
    0 1px 2px rgba(0,0,0,0.10),
    inset 0 1px 3px rgba(255,255,255,0.30);
}

.slot.filled-red .slot-circle {
  background: radial-gradient(ellipse 60% 50% at 35% 30%, rgba(255,255,255,0.35) 0%, transparent 70%), var(--red);
  border-color: var(--red);
  box-shadow:
    0 3px 6px rgba(239, 45, 45, 0.35),
    0 1px 2px rgba(0,0,0,0.10),
    inset 0 1px 3px rgba(255,255,255,0.30);
}

/* ===== Addition Bar ===== */
.addition-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--gray-bg);
  border: 1px solid var(--gray-border);
  border-radius: 14px;
  padding: 12px 24px;
}

.num-card {
  background: #fff;
  border: 1px solid var(--gray-border);
  border-radius: 10px;
  min-width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 700;
  padding: 0 12px;
}

.num-card--blue { color: var(--blue); }
.num-card--red  { color: var(--red); }
.num-card--sum  { color: #222; }

/* Coverable card (blue, red, sum) */
.num-card--coverable {
  position: relative;
  cursor: pointer;
  overflow: hidden;
}

.num-card--coverable:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

/* Generic number cover (replaces old .sum-cover) */
.num-cover {
  position: absolute;
  inset: 0;
  background: #fff;
  border-radius: 9px;
  transition: opacity 0.3s;
}

.num-cover.revealed {
  opacity: 0;
  pointer-events: none;
}

.op-sign {
  font-size: 26px;
  font-weight: 600;
  color: #555;
}

/* ===== Animations ===== */

/* Flying chip clone (single) — 3D raised */
.flying-chip {
  position: fixed;
  width: var(--chip-size);
  height: var(--chip-size);
  border-radius: 50%;
  z-index: 1000;
  pointer-events: none;
  will-change: transform, opacity;
}

.flying-chip--blue {
  background: radial-gradient(ellipse 60% 50% at 35% 30%, rgba(255,255,255,0.35) 0%, transparent 70%), var(--blue);
  box-shadow: 0 3px 8px rgba(26, 106, 255, 0.4), inset 0 1px 2px rgba(255,255,255,0.25);
}

.flying-chip--red {
  background: radial-gradient(ellipse 60% 50% at 35% 30%, rgba(255,255,255,0.35) 0%, transparent 70%), var(--red);
  box-shadow: 0 3px 8px rgba(239, 45, 45, 0.4), inset 0 1px 2px rgba(255,255,255,0.25);
}

/* Flying bundle (5er cluster) — 3D raised */
.flying-bundle {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  will-change: transform, opacity;
}

.flying-bundle .bundle-chip {
  position: absolute;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.4);
}

.flying-bundle .bundle-chip--blue {
  background: radial-gradient(ellipse 55% 45% at 35% 30%, rgba(255,255,255,0.30) 0%, transparent 65%), var(--blue);
  box-shadow: 0 2px 4px rgba(26, 106, 255, 0.3);
}

.flying-bundle .bundle-chip--red {
  background: radial-gradient(ellipse 55% 45% at 35% 30%, rgba(255,255,255,0.30) 0%, transparent 65%), var(--red);
  box-shadow: 0 2px 4px rgba(239, 45, 45, 0.3);
}

/* Shake */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

.shake {
  animation: shake 0.35s ease;
}

/* Pop-in for slot fill */
@keyframes popIn {
  0%   { transform: scale(0.3); opacity: 0; }
  70%  { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

.slot-pop {
  animation: popIn 0.3s ease-out;
}

/* Fade-out for removal */
@keyframes fadeOut {
  0%   { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.3) translateY(-30px); opacity: 0; }
}

.slot-fadeout .slot-circle {
  animation: fadeOut 0.35s ease-in forwards;
}

/* Reset sweep */
@keyframes sweepAway {
  0%   { transform: scale(1) translate(0, 0); opacity: 1; }
  100% { transform: scale(0.4) translate(var(--sweep-x, 20px), -60px); opacity: 0; }
}

.slot-sweep .slot-circle {
  animation: sweepAway 0.4s ease-in forwards;
}

/* ===== Dragon Footer (decorative) ===== */
.dragon-footer {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 8px 8px;
  margin-top: 8px;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  overflow: visible;
}

.dragon {
  flex-shrink: 0;
  opacity: 0.88;
  overflow: visible;
}

.dragon img {
  display: block;
  height: auto;
  max-height: 140px;
  width: auto;
  pointer-events: none;
  -webkit-user-drag: none;
}

/* Zahlix (green): clean image, no patch needed */
.dragon--green img {
  /* nothing extra */
}

/* Zahline (red): new cleaned image, no crop needed */
.dragon--red img {
  /* clip-path removed — ZAHLINE.png is already clean */
}

/* ===== Responsive ===== */
@media (max-width: 720px) {
  :root {
    --chip-size: 38px;
    --chip-size-toolbar: 28px;
    --ship-gap: 10px;
  }

  .app { gap: 20px; }
  .toolbar { padding: 6px 8px; gap: 4px; flex-wrap: wrap; }
  .toolbar-group { gap: 4px; }
  .tool-btn { padding: 5px 6px; }
  .ship-half { padding: 12px 14px; gap: 4px; }
  .addition-bar { padding: 10px 14px; gap: 8px; }
  .num-card { min-width: 42px; height: 42px; font-size: 22px; }
  .op-sign { font-size: 20px; }

  .dragon img { max-height: 110px; }
}

@media (max-width: 480px) {
  :root {
    --chip-size: 28px;
    --chip-size-toolbar: 24px;
    --ship-gap: 8px;
  }

  .tool-btn { padding: 4px 5px; }
  .ship-half { padding: 10px 12px; gap: 3px; border-radius: 30px; }
  .num-card { min-width: 36px; height: 36px; font-size: 18px; padding: 0 8px; }
  .addition-bar { gap: 6px; }
  .op-sign { font-size: 18px; }
  .chip-label { font-size: 11px; }

  .dragon-footer { gap: 12px; padding: 0 4px; }
  .dragon img { max-height: 85px; }
}
