/* =========================================================
   DARK THEME COIN FLIP — style.css
   ========================================================= */

:root {
  --bg:        #0a0c12;
  --panel:     rgba(255, 255, 255, .035);
  --panel-2:   rgba(255, 255, 255, .06);
  --border:    rgba(255, 255, 255, .09);
  --text:      #e8ecf4;
  --muted:     #8b93a7;

  --gold:      #f2c14e;
  --gold-dark: #a97a1f;
  --silver:    #cdd6e4;
  --silver-drk:#7d8798;
  --accent:    #6c8cff;

  --radius:    16px;
  --shadow:    0 18px 40px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  padding: 32px 16px 48px;
  display: flex;
  justify-content: center;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Nền phát sáng ---------- */
.bg-glow {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(600px 420px at 10% -8%,  rgba(242, 193, 78, .14), transparent 70%),
    radial-gradient(700px 460px at 98% 2%,   rgba(108, 140, 255, .14), transparent 70%),
    radial-gradient(800px 520px at 50% 115%, rgba(205, 214, 228, .07), transparent 70%);
}

/* ---------- Layout ---------- */
.app {
  position: relative;
  z-index: 1;
  width: min(940px, 100%);
  display: grid;
  gap: 18px;
}

.app__header { text-align: center; }

.app__header h1 {
  margin: 0 0 6px;
  font-size: clamp(1.7rem, 4.2vw, 2.4rem);
  letter-spacing: -.02em;
  background: linear-gradient(180deg, #fff 10%, var(--gold) 120%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.app__header p {
  margin: 0;
  color: var(--muted);
  font-size: .92rem;
}

kbd {
  padding: 2px 7px;
  font-size: .78rem;
  font-family: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 6px;
}

.app__footer {
  text-align: center;
  color: var(--muted);
  font-size: .82rem;
  padding-top: 4px;
}

/* ---------- Panel ---------- */
.panel {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.panel__title {
  margin: 0 0 14px;
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- Điều khiển ---------- */
.controls { display: grid; gap: 16px; }

.controls__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.controls__row label {
  font-weight: 600;
  font-size: .95rem;
}

#coinCountOut {
  min-width: 58px;
  text-align: center;
  padding: 5px 12px;
  font-weight: 800;
  font-size: 1rem;
  color: #3a2704;
  background: linear-gradient(180deg, #ffd873, var(--gold));
  border-radius: 999px;
  box-shadow: 0 6px 16px rgba(242, 193, 78, .25);
}

/* --- Range slider --- */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  margin: 2px 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gold), var(--accent));
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid #0a0c12;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .35), 0 6px 14px rgba(0, 0, 0, .65);
  cursor: grab;
  transition: transform .15s ease;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.08); }
input[type="range"]:active::-webkit-slider-thumb { cursor: grabbing; }

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid #0a0c12;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .35), 0 6px 14px rgba(0, 0, 0, .65);
  cursor: grab;
}
input[type="range"]::-moz-range-track {
  height: 8px;
  border-radius: 999px;
  background: transparent;
}

input[type="range"]:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 4px rgba(108, 140, 255, .5);
}

/* --- Nút chọn nhanh --- */
.controls__quick {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.controls__quick button {
  font: inherit;
  font-size: .85rem;
  font-weight: 700;
  color: var(--muted);
  padding: 7px 14px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: all .18s ease;
}
.controls__quick button:hover {
  color: var(--text);
  background: var(--panel-2);
  border-color: rgba(255, 255, 255, .2);
}
.controls__quick button.is-active {
  color: #3a2704;
  background: linear-gradient(180deg, #ffd873, var(--gold));
  border-color: transparent;
  box-shadow: 0 6px 16px rgba(242, 193, 78, .22);
}

/* --- Nút hành động --- */
.controls__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.btn {
  font: inherit;
  font-weight: 600;
  color: var(--text);
  padding: 11px 20px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: transform .15s, background .2s, border-color .2s, box-shadow .2s;
}
.btn:hover { background: rgba(255, 255, 255, .1); }
.btn:active { transform: translateY(1px) scale(.99); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn--primary {
  flex: 1 1 160px;
  color: #3a2704;
  background: linear-gradient(180deg, #ffd873, var(--gold));
  border-color: rgba(255, 255, 255, .25);
  box-shadow: 0 10px 24px rgba(242, 193, 78, .22);
}
.btn--primary:hover {
  background: linear-gradient(180deg, #ffe08f, #f7c95c);
  box-shadow: 0 12px 28px rgba(242, 193, 78, .3);
}

.btn--ghost { background: transparent; }

.btn--icon {
  padding: 11px 14px;
  font-size: 1rem;
  line-height: 1;
}
.btn--icon[aria-pressed="false"] { opacity: .45; }

/* ---------- Thống kê ---------- */
.stats { display: grid; gap: 16px; }

.stats__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 12px;
}

.stat {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  background: rgba(0, 0, 0, .22);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.stat__label {
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat__value {
  font-size: 1.5rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
}
.stat__value--gold   { color: var(--gold); }
.stat__value--silver { color: var(--silver); }

/* --- Thanh tỉ lệ --- */
.bar {
  position: relative;
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: linear-gradient(90deg, rgba(205, 214, 228, .35), rgba(205, 214, 228, .2));
  border: 1px solid var(--border);
}

.bar__heads {
  height: 100%;
  width: 0;
  border-radius: 999px 0 0 999px;
  background: linear-gradient(90deg, #ffdf8a, var(--gold) 55%, var(--gold-dark));
  box-shadow: 0 0 18px rgba(242, 193, 78, .45);
  transition: width .55s cubic-bezier(.22, .85, .3, 1);
}

.bar__legend {
  display: flex;
  justify-content: space-between;
  font-size: .8rem;
  color: var(--muted);
}
.bar__legend b { color: var(--text); font-variant-numeric: tabular-nums; }

/* ---------- Sân tung xu ---------- */
.board__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}

#lastResult {
  font-size: .92rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.coins {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 14px 12px;
  justify-items: center;
  align-content: start;
  min-height: 96px;
  max-height: 46vh;
  overflow-y: auto;
  padding: 4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, .18) transparent;
}
.coins::-webkit-scrollbar { width: 8px; }
.coins::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, .16);
  border-radius: 999px;
}

/* --- Kích thước theo số lượng --- */
.coins--compact { grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 10px 8px; }
.coins--compact .coin { max-width: 48px; font-size: 15px; }

.coins--dense { grid-template-columns: repeat(auto-fill, minmax(30px, 1fr)); gap: 8px 6px; }
.coins--dense .coin { max-width: 34px; font-size: 11px; }

/* --- Đồng xu 3D --- */
.coin {
  position: relative;
  width: 100%;
  max-width: 64px;
  aspect-ratio: 1 / 1;
  font-size: 20px;
  perspective: 700px;
}

.coin__inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transform: rotateY(0deg);
  transition: transform 620ms cubic-bezier(.2, .8, .25, 1);
  will-change: transform;
}

.coin__face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 1em;
  font-weight: 900;
  user-select: none;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transition: box-shadow .3s ease;
}

.coin__face--heads {
  color: #4a3206;
  background: radial-gradient(circle at 32% 26%, #ffeeb4, var(--gold) 46%, var(--gold-dark) 100%);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, .4),
    inset 0 -6px 12px rgba(0, 0, 0, .28),
    0 6px 14px rgba(0, 0, 0, .45);
  transform: rotateY(0deg);
}

.coin__face--tails {
  color: #2c3442;
  background: radial-gradient(circle at 32% 26%, #ffffff, var(--silver) 46%, var(--silver-drk) 100%);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, .5),
    inset 0 -6px 12px rgba(0, 0, 0, .25),
    0 6px 14px rgba(0, 0, 0, .45);
  transform: rotateY(180deg);
}

/* Đồng xu chưa tung */
.coin--idle .coin__inner {
  opacity: .38;
  filter: grayscale(.65);
}

/* Hiệu ứng khi đang tung */
.coin.is-flipping { z-index: 2; }
.coin.is-flipping .coin__inner { filter: drop-shadow(0 0 12px rgba(242, 193, 78, .35)); }

/* Viền sáng theo kết quả */
.coin--heads .coin__face--heads {
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, .4),
    inset 0 -6px 12px rgba(0, 0, 0, .28),
    0 0 16px rgba(242, 193, 78, .55);
}
.coin--tails .coin__face--tails {
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, .5),
    inset 0 -6px 12px rgba(0, 0, 0, .25),
    0 0 16px rgba(205, 214, 228, .45);
}

/* ---------- Lịch sử ---------- */
.history__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  max-height: 230px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, .18) transparent;
}
.history__list::-webkit-scrollbar { width: 8px; }
.history__list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, .16);
  border-radius: 999px;
}

.history__list:empty::after {
  content: "Chưa có lượt tung nào.";
  color: var(--muted);
  font-size: .88rem;
}

.history__item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  font-size: .88rem;
  background: rgba(0, 0, 0, .22);
  border: 1px solid var(--border);
  border-radius: 10px;
  animation: slideIn .3s ease both;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.history__time {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: .8rem;
  flex: 0 0 auto;
}

.history__detail {
  color: var(--muted);
  flex: 1 1 auto;
}

.history__split {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.history__split b { font-weight: 800; }
.history__split .gold   { color: var(--gold); }
.history__split .silver { color: var(--silver); }

/* ---------- Responsive ---------- */
@media (max-width: 560px) {
  body { padding: 20px 12px 32px; }
  .panel { padding: 16px; border-radius: 14px; }
  .controls__actions { flex-wrap: wrap; }
  .btn--primary { flex: 1 1 100%; order: -1; }
  .stat__value { font-size: 1.25rem; }
}

/* ---------- Giảm chuyển động ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}