:root {
  color-scheme: dark;
  --ink: #11101d;
  --ink-soft: #1d1b2e;
  --paper: #fff8e8;
  --muted: #aaa6b8;
  --gold: #ffd75e;
  --gold-deep: #c98912;
  --coral: #ff6f61;
  --mint: #64e5ba;
  --line: rgba(255, 248, 232, .15);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100svh;
  background:
    radial-gradient(circle at 12% 6%, rgba(255, 111, 97, .2), transparent 28rem),
    radial-gradient(circle at 88% 92%, rgba(100, 229, 186, .15), transparent 30rem),
    var(--ink);
  color: var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.coin-tool {
  width: min(1180px, 100%);
  min-height: 100svh;
  margin: auto;
  padding: clamp(18px, 3vw, 36px);
}

.tool-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: clamp(18px, 3vh, 30px);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--mint);
  font-size: .7rem;
  font-weight: 950;
  letter-spacing: .2em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2.5rem, 7vw, 5.8rem);
  line-height: .88;
  letter-spacing: -.07em;
}

h1 em { color: var(--gold); font-family: Georgia, serif; font-weight: 500; }

.fairness {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 260px;
  margin: 0;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 750;
  line-height: 1.4;
}

.fairness span { width: 9px; height: 9px; flex: 0 0 auto; border-radius: 50%; background: var(--mint); box-shadow: 0 0 0 5px rgba(100, 229, 186, .12); }

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(310px, .72fr);
  min-height: min(650px, calc(100svh - 170px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 30px;
  background: rgba(29, 27, 46, .78);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .35);
}

.coin-panel {
  position: relative;
  display: grid;
  grid-template-rows: 1fr auto;
  place-items: center;
  min-height: 560px;
  overflow: hidden;
  padding: clamp(24px, 5vw, 56px);
  border-right: 1px solid var(--line);
  background:
    linear-gradient(rgba(255, 255, 255, .025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .025) 1px, transparent 1px),
    #171526;
  background-size: 34px 34px;
}

.halo { position: absolute; border: 1px solid rgba(255, 215, 94, .18); border-radius: 50%; pointer-events: none; }
.halo-one { width: 490px; height: 490px; top: 48%; left: 50%; transform: translate(-50%, -58%); }
.halo-two { width: 370px; height: 370px; top: 48%; left: 50%; transform: translate(-50%, -58%); border-style: dashed; animation: orbit 24s linear infinite; }

@keyframes orbit { to { transform: translate(-50%, -58%) rotate(360deg); } }

.coin-scene { width: clamp(190px, 29vw, 300px); aspect-ratio: 1; perspective: 1000px; z-index: 1; align-self: end; margin-bottom: clamp(16px, 4vh, 34px); }

.coin {
  --coin-turn: 0deg;
  position: relative;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #312006;
  cursor: pointer;
  transform: rotateY(var(--coin-turn));
  transform-style: preserve-3d;
  transition: transform 1.05s cubic-bezier(.16, .82, .2, 1);
  filter: drop-shadow(0 28px 25px rgba(0, 0, 0, .38));
}

.coin:not(:disabled):hover { filter: drop-shadow(0 32px 28px rgba(0, 0, 0, .46)) brightness(1.04); }
.coin:focus-visible { outline: 4px solid var(--mint); outline-offset: 8px; }
.coin:disabled { cursor: wait; }

.coin-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  border: clamp(10px, 1.5vw, 16px) double #a96c0b;
  border-radius: 50%;
  backface-visibility: hidden;
  background:
    radial-gradient(circle at 34% 25%, #fff1a4 0 8%, transparent 9%),
    radial-gradient(circle at 45% 38%, #ffe779, #e8ac2f 67%, #a86608 100%);
  box-shadow:
    inset 0 0 0 5px #f7c84a,
    inset 0 0 0 8px rgba(95, 55, 0, .3),
    0 0 0 3px #754300;
  -webkit-backface-visibility: hidden;
}

.coin-face { transform: translateZ(9px); }
.coin-letter { font-family: Georgia, serif; font-size: clamp(5.2rem, 13vw, 9.3rem); font-weight: 900; line-height: .8; text-shadow: 0 3px 0 rgba(255, 249, 187, .6); }
.coin-label { margin-top: 14px; font-size: clamp(.65rem, 1.6vw, .85rem); font-weight: 950; letter-spacing: .24em; text-transform: uppercase; }

.result-block { position: relative; z-index: 2; text-align: center; }
.result-kicker { margin: 0 0 6px; color: var(--coral); font-size: .66rem; font-weight: 950; letter-spacing: .18em; text-transform: uppercase; }
.result { margin: 0; font-size: clamp(1.15rem, 3vw, 1.7rem); font-weight: 900; }

.control-card { display: flex; flex-direction: column; padding: clamp(24px, 3vw, 38px); background: rgba(16, 15, 29, .68); }
.tool-copy { padding-bottom: clamp(18px, 4vh, 34px); border-bottom: 1px solid var(--line); }
.tool-copy p { margin: 0 0 10px; color: var(--mint); font-size: .66rem; font-weight: 950; letter-spacing: .16em; text-transform: uppercase; }
.tool-copy h2 { margin: 0; font-size: clamp(1.7rem, 3.6vw, 2.8rem); line-height: .98; letter-spacing: -.05em; }
.tool-copy span { display: block; margin-top: 12px; color: var(--muted); font-size: .74rem; line-height: 1.45; }

.flip-button { display: flex; align-items: center; justify-content: space-between; width: 100%; margin-top: 16px; padding: 14px 16px 14px 20px; border: 0; border-radius: 15px; background: var(--gold); color: #241706; box-shadow: 0 6px 0 var(--gold-deep); font-weight: 950; cursor: pointer; }
.flip-button b { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--ink); color: var(--paper); }
.flip-button:not(:disabled):hover { transform: translateY(2px); box-shadow: 0 4px 0 var(--gold-deep); }
.flip-button:focus-visible, .history-heading button:focus-visible { outline: 3px solid var(--mint); outline-offset: 3px; }
.flip-button:disabled { opacity: .65; cursor: wait; }
.shortcut { margin: 10px 0 20px; color: var(--muted); font-size: .68rem; text-align: center; }
kbd { padding: 2px 6px; border: 1px solid var(--line); border-radius: 5px; background: var(--ink-soft); color: var(--paper); font: inherit; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin: 0; }
.stats div { padding: 10px 5px; border: 1px solid var(--line); border-radius: 11px; text-align: center; }
.stats dt { color: var(--muted); font-size: .57rem; font-weight: 850; letter-spacing: .07em; text-transform: uppercase; }
.stats dd { margin: 4px 0 0; color: var(--paper); font-size: 1.25rem; font-weight: 950; }

.history-block { margin-top: 20px; }
.history-heading { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: .67rem; font-weight: 900; letter-spacing: .1em; text-transform: uppercase; }
.history-heading button { padding: 4px 0; border: 0; background: transparent; color: var(--coral); font-size: .64rem; font-weight: 900; cursor: pointer; }
.history { display: flex; gap: 7px; min-height: 31px; margin: 10px 0 0; padding: 0; list-style: none; }
.history li { display: grid; place-items: center; width: 31px; height: 31px; border: 1px solid #8e5d0d; border-radius: 50%; background: var(--gold); color: #352207; font-family: Georgia, serif; font-weight: 900; }
.history .empty { display: block; width: auto; height: auto; border: 0; background: transparent; color: #6f6b7d; font-family: inherit; font-size: .7rem; font-weight: 700; }

details { margin-top: auto; padding-top: 20px; color: var(--muted); font-size: .68rem; line-height: 1.45; }
summary { color: var(--paper); font-weight: 850; cursor: pointer; }
details p { margin: 8px 0 0; }

@media (max-width: 820px) {
  .tool-header { align-items: start; }
  .workspace { grid-template-columns: 1fr; }
  .coin-panel { min-height: 480px; border-right: 0; border-bottom: 1px solid var(--line); }
  .control-card { min-height: 460px; }
}

@media (max-width: 520px) {
  .coin-tool { padding: 14px; }
  .tool-header { display: block; }
  .fairness { margin-top: 15px; }
  .workspace { border-radius: 22px; }
  .coin-panel { min-height: 420px; padding: 28px 18px; }
  .halo-one { width: 380px; height: 380px; }
  .halo-two { width: 290px; height: 290px; }
  .control-card { padding: 24px 18px; }
}

@media (prefers-reduced-motion: reduce) {
  .halo-two { animation: none; }
  .coin { transition-duration: .01s; }
  * { scroll-behavior: auto !important; }
}
