:root {
  --bg-1: #1e1b4b;
  --bg-2: #4338ca;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #f59e0b;
  --accent-dark: #d97706;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: start center;
  padding: 2rem 1rem;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top, var(--bg-2), var(--bg-1));
}

.card {
  width: 100%;
  max-width: 400px;
  padding: 2rem 1.5rem;
  text-align: center;
  background: var(--card);
  border-radius: 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .35);
}

h1 { margin: 0; font-size: 2rem; letter-spacing: -.02em; }
.subtitle { margin: .25rem 0 0; color: var(--muted); }

.coin-stage { perspective: 800px; margin: 1.5rem 0 1rem; }

.coin {
  width: 200px;
  height: 200px;
  margin: 0 auto;
  border-radius: 50%;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 12px 25px rgba(0, 0, 0, .3);
}

.coin img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1.12);
}

.coin.flipping { animation: flip .9s ease-in-out; }

@keyframes flip {
  0%   { transform: rotateY(0) translateY(0); }
  50%  { transform: rotateY(900deg) translateY(-40px); }
  100% { transform: rotateY(1800deg) translateY(0); }
}

.result {
  min-height: 4.5rem;
  font-size: 1.5rem;
  line-height: 1.4;
}

.result .winner { font-weight: 800; color: var(--accent-dark); }
.result .score { display: block; font-size: 1rem; color: var(--muted); }

.controls { margin-top: 1rem; }
.controls label { display: block; margin-bottom: .5rem; font-size: .9rem; color: var(--muted); }
.row { display: flex; gap: .5rem; justify-content: center; }

select, button {
  font: inherit;
  padding: .7rem 1rem;
  border-radius: 12px;
  border: 1px solid #d1d5db;
}

select {
  min-width: 5rem;
  padding-right: 2.5rem;
  background-color: #f9fafb;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  -webkit-appearance: none;
  appearance: none;
}

button {
  min-width: 6rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
  cursor: pointer;
  transition: background .15s, transform .1s;
}

button:hover:not(:disabled) { background: var(--accent-dark); }
button:active:not(:disabled) { transform: scale(.96); }
button:disabled { opacity: .6; cursor: wait; }

.history { margin-top: 1.75rem; padding-top: 1rem; border-top: 1px solid #e5e7eb; text-align: left; }
.history-head { display: flex; justify-content: space-between; align-items: center; }
.history h2 { margin: 0; font-size: 1rem; }

button.link-btn {
  min-width: 0;
  padding: .25rem .5rem;
  font-size: .85rem;
  font-weight: 500;
  color: var(--muted);
  background: none;
  border: none;
}
button.link-btn:hover:not(:disabled) { background: none; color: #dc2626; }

.history-list { list-style: none; margin: .5rem 0 0; padding: 0; max-height: 220px; overflow-y: auto; }
.history-list li {
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  padding: .45rem 0;
  font-size: .9rem;
  border-bottom: 1px solid #f3f4f6;
}
.entry-main { display: flex; align-items: center; gap: .5rem; }
.entry-detail { color: var(--muted); font-size: .8rem; }
.badge {
  min-width: 3.5rem;
  padding: .15rem .6rem;
  border-radius: 999px;
  font-size: .85rem;
  font-weight: 800;
  text-align: center;
}
.badge-head { color: #92400e; background: #fef3c7; }
.badge-tail { color: #3730a3; background: #e0e7ff; }
.history-list li { align-items: center; }
.history-list time { color: var(--muted); font-variant-numeric: tabular-nums; }
.history-list .empty { color: var(--muted); justify-content: center; border: none; }

.card { position: relative; }

.lang-switch { position: absolute; top: .75rem; right: .75rem; display: flex; gap: .25rem; }
button.lang-btn {
  min-width: 0;
  padding: .25rem .55rem;
  font-size: .75rem;
  font-weight: 700;
  color: var(--muted);
  background: #f3f4f6;
  border: 1px solid transparent;
  border-radius: 8px;
}
button.lang-btn:hover:not(:disabled) { background: #e5e7eb; }
button.lang-btn.active { color: #fff; background: var(--bg-2); }
button.lang-btn.active:hover:not(:disabled) { background: var(--bg-2); }

.about { margin-top: 1.25rem; text-align: left; font-size: .9rem; }
.about details { border-top: 1px solid #e5e7eb; padding: .6rem 0; }
.about summary { cursor: pointer; font-weight: 600; }
.about p, .about ul { margin: .5rem 0 0; color: var(--muted); line-height: 1.5; }
.about ul { padding-left: 1.1rem; }
.about li + li { margin-top: .4rem; }

.disclaimer {
  margin: 1rem 0 0;
  padding-top: .75rem;
  border-top: 1px solid #e5e7eb;
  font-size: .75rem;
  font-style: italic;
  line-height: 1.5;
  color: var(--muted);
}

:focus-visible { outline: 3px solid #818cf8; outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .coin.flipping { animation: none; }
}
