/* ===================================================================
   Coin Flip — style
   Zero dependencies. Pure CSS. Premium feel.
   =================================================================== */

/* ============ Design tokens ============ */
:root {
  --bg: #faf6f1;
  --bg-2: #f3eee5;
  --surface: #ffffff;
  --surface-2: #faf6ed;
  --surface-3: #eee7d8;
  --border: #e8dfcc;
  --border-soft: #f0e9da;
  --text: #1f1a14;
  --text-2: #5c5547;
  --text-3: #6e6557;
  --text-faint: #b5ac9b;
  --accent: #e85f4d;
  --accent-2: #d44a39;
  --accent-soft: rgba(232, 95, 77, 0.10);
  --accent-glow: rgba(232, 95, 77, 0.30);
  --success: #3a9d6f;
  --r-sm: 8px;
  --r-md: 12px;
  --r-xl: 20px;
  --r-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 24px 48px rgba(0,0,0,0.12);
  --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
  --font-ui: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI",
             "PingFang TC", "PingFang SC", "Hiragino Sans", "Noto Sans CJK",
             sans-serif;
  --font-mono: "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

/* ============ Reset ============ */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
html, body {
  font-family: var(--font-ui);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "kern" 1, "liga" 1, "calt" 1, "ss01" 1;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select { font-family: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-2); }
ul, ol { padding-left: 1.25em; }

/* ============ Body ============ */
body {
  background: radial-gradient(ellipse at 50% 0%, #fdfaf3 0%, var(--bg) 50%);
  background-attachment: fixed;
}

/* ============ Layout ============ */
.app {
  max-width: 620px;
  margin: 0 auto;
  padding: 20px 20px 40px;
}

/* ============ Top bar ============ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0 20px;
}
.brand {
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
  letter-spacing: -0.01em;
}
.brand:hover { color: var(--text); opacity: 0.7; }
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.nav-link {
  font-size: 13px;
  color: var(--text-3);
  white-space: nowrap;
  transition: color var(--transition);
}
.nav-link:hover { color: var(--accent); }

/* ============ Lang switcher ============ */
.lang-switcher {
  appearance: none;
  -webkit-appearance: none;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 6px 28px 6px 10px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238a8275'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.lang-switcher:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.lang-switcher:hover { border-color: var(--accent); }

/* ============ Page title ============ */
.page-title {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
  text-align: center;
  margin-top: 4px;
}
.page-sub {
  font-size: 14px;
  color: var(--text-2);
  text-align: center;
  margin: 6px 0 28px;
  letter-spacing: -0.01em;
}

/* ============ Workspace ============ */
.workspace {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

/* ============ Coin stage ============ */
.coin-stage {
  position: relative;
  width: 316px;
  height: 316px;
  margin: 0 auto 24px;
  padding: 18px 18px 22px;
  border-radius: 28px;
  background:
    radial-gradient(ellipse at 50% 100%, rgba(0,0,0,0.06) 0%, rgba(0,0,0,0) 55%),
    linear-gradient(180deg, #fffdf7 0%, var(--surface-2) 55%, var(--surface-3) 100%);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.9),
    inset 0 -1px 0 rgba(0,0,0,0.04),
    0 1px 2px rgba(0,0,0,0.03),
    0 18px 36px -16px rgba(60,40,10,0.18),
    0 2px 6px rgba(0,0,0,0.04);
  border: 1px solid var(--border-soft);
}

.coin-stage::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 14px;
  width: 70%;
  height: 18px;
  transform: translateX(-50%);
  background: radial-gradient(ellipse at center, rgba(80,55,12,0.18) 0%, rgba(80,55,12,0) 70%);
  filter: blur(2px);
  pointer-events: none;
  z-index: 0;
  transition: transform 220ms ease-out, opacity 220ms ease-out;
}

.coin-stage.is-flipping::before {
  transform: translateX(-50%) scaleX(0.55);
  opacity: 0.7;
}

.coin-canvas {
  display: block;
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 1;
  border-radius: var(--r-xl);
  animation: coinIdle 4200ms ease-in-out infinite;
}

.coin-stage.is-flipping .coin-canvas {
  animation: none;
}

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

.coin-stage.is-booting .coin-canvas {
  animation: coinBoot 460ms cubic-bezier(0.34, 1.56, 0.64, 1) 1;
}

@keyframes coinBoot {
  0%   { transform: translateY(-6px) rotate(-3deg); opacity: 0.6; }
  60%  { transform: translateY(2px)  rotate(2deg);  opacity: 1; }
  100% { transform: translateY(0)    rotate(0);     opacity: 1; }
}

.result-label {
  position: absolute;
  left: 50%;
  bottom: -38px;
  transform: translateX(-50%) translateY(-2px);
  min-width: 160px;
  padding: 4px 14px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--accent);
  text-align: center;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  opacity: 0;
  transition: opacity var(--transition), transform var(--transition);
  z-index: 2;
}
.result-label.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============ Flip button ============ */
.btn-flip {
  position: relative;
  margin-top: 32px;
  background: linear-gradient(180deg, #ed7060 0%, var(--accent) 55%, var(--accent-2) 100%);
  color: #fff;
  border-radius: var(--r-md);
  padding: 14px 32px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.35),
    inset 0 -1px 0 rgba(0,0,0,0.18),
    0 1px 2px rgba(0,0,0,0.06),
    0 6px 14px var(--accent-glow);
  transition: transform 90ms ease-out, box-shadow var(--transition), filter var(--transition), opacity var(--transition);
  user-select: none;
  -webkit-user-select: none;
  min-width: 160px;
}
.btn-flip:hover {
  filter: brightness(1.04);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.4),
    inset 0 -1px 0 rgba(0,0,0,0.18),
    0 2px 4px rgba(0,0,0,0.06),
    0 10px 22px var(--accent-glow);
}
.btn-flip:active {
  transform: translateY(1px);
  box-shadow:
    inset 0 2px 4px rgba(0,0,0,0.22),
    inset 0 -1px 0 rgba(255,255,255,0.18),
    0 1px 2px var(--accent-glow);
}
.btn-flip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
.btn-flip:disabled,
.btn-flip.is-flipping {
  opacity: 0.55;
  cursor: not-allowed;
  filter: grayscale(0.25);
  transform: scale(0.97);
  box-shadow:
    inset 0 1px 2px rgba(0,0,0,0.12),
    0 1px 2px rgba(0,0,0,0.04);
  pointer-events: none;
}

.shortcut-hint {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 6px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ============ Stats bar ============ */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 28px;
  padding: 14px 14px;
  background: linear-gradient(180deg, #f6efe0 0%, #ece3cf 100%);
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  box-shadow:
    inset 0 1px 2px rgba(80,55,12,0.10),
    inset 0 -1px 0 rgba(255,255,255,0.5),
    0 1px 0 rgba(255,255,255,0.6);
  width: 100%;
  max-width: 420px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 4px;
  background: #faf6ea;
  border-radius: var(--r-sm);
  border: 1px solid rgba(140,90,15,0.10);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.7),
    inset 0 -1px 0 rgba(80,55,12,0.05);
  min-width: 0;
}

.stat-num {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  letter-spacing: -0.01em;
  text-shadow: 0 1px 0 rgba(255,255,255,0.7);
  line-height: 1.1;
}

.stat-label {
  font-size: 10px;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-align: center;
  line-height: 1.2;
}

/* ============ History ============ */
.btn-history-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  margin-top: 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  transition: background var(--transition), border-color var(--transition);
}
.btn-history-toggle:hover {
  background: var(--surface-2);
  border-color: var(--text-faint);
}
.btn-history-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn-history-toggle .chevron {
  transition: transform var(--transition);
}
.btn-history-toggle[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
}

.history-panel {
  width: 100%;
  max-width: 420px;
  margin-top: 0;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 280ms cubic-bezier(0.4, 0, 0.2, 1),
              opacity 200ms ease-out,
              margin-top 280ms cubic-bezier(0.4, 0, 0.2, 1);
}

.history-panel.is-open {
  max-height: 640px;
  opacity: 1;
  margin-top: 8px;
}

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

.history-count {
  font-size: 12px;
  color: var(--text-3);
}

.btn-text {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-3);
  padding: 4px 8px;
  border-radius: var(--r-sm);
  transition: color var(--transition), background var(--transition);
}
.btn-text:hover {
  color: var(--text-2);
  background: var(--accent-soft);
}
.btn-text-danger:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.history-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.history-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: -0.01em;
  animation: chipIn 250ms ease-out both;
}

.history-chip.heads {
  background: var(--accent-soft);
  color: var(--accent);
}

.history-chip.tails {
  background: rgba(58, 157, 111, 0.10);
  color: var(--success);
}

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

.history-empty {
  font-size: 13px;
  color: var(--text-faint);
  text-align: center;
  padding: 20px 0;
}

/* ============ Info section ============ */
.info {
  margin-top: 56px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
}

.info h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin: 28px 0 10px;
  letter-spacing: -0.02em;
}

.info h2:first-child {
  margin-top: 0;
}

.info h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin: 20px 0 6px;
  letter-spacing: -0.01em;
}

.info p {
  font-size: 14px;
  line-height: 1.65;
  color: var(--text-2);
  margin-bottom: 8px;
}

.info ol {
  margin-bottom: 8px;
}

.info li {
  font-size: 14px;
  line-height: 1.65;
  color: var(--text-2);
  margin-bottom: 6px;
}

.info em {
  font-style: italic;
  color: var(--text);
}

/* ============ Footer ============ */
.site-footer {
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  text-align: center;
}

.site-footer-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 20px;
  font-size: 13px;
  color: var(--text-3);
}

.site-footer-row a {
  color: var(--text-3);
  font-size: 13px;
  transition: color var(--transition);
}
.site-footer-row a:hover { color: var(--accent); }

.sub {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 10px;
}

/* ============ Focus / A11y ============ */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============ Responsive ============ */
@media (max-width: 480px) {
  .app {
    padding: 12px 16px 32px;
  }

  .page-title {
    font-size: 26px;
  }

  .coin-stage {
    width: 276px;
    height: 276px;
  }

  .stats-bar {
    padding: 10px 10px;
    gap: 6px;
  }

  .stat-num {
    font-size: 17px;
  }

  .stat-label {
    font-size: 9px;
    letter-spacing: 0.05em;
  }

  .stats-bar {
    gap: 16px;
    padding: 12px 16px;
  }

  .stat-num {
    font-size: 18px;
  }

  .topbar-right {
    gap: 8px;
  }

  .lang-switcher {
    font-size: 12px;
    padding: 5px 24px 5px 8px;
  }
}
