:root {
  --bg: #120308;
  --card: #2a0f19;
  --card-soft: #3a1622;
  --text: #ffeedd;
  --muted: #d3bca9;
  --primary: #f6bd5d;
  --accent: #ffcf74;
  --accent-strong: #ffda8e;
  --danger: #ff8a8a;
  --ok: #8ae09b;
  --border: rgba(255, 186, 106, 0.34);
  --red-glow: rgba(255, 70, 101, 0.45);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 0%, rgba(213, 39, 72, 0.34) 0%, transparent 45%),
    radial-gradient(circle at 82% 10%, rgba(255, 191, 87, 0.25) 0%, transparent 36%),
    linear-gradient(160deg, #25060f 0%, var(--bg) 62%);
  font-family: "Segoe UI", Tahoma, sans-serif;
}

.app-shell {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 14px 12px calc(16px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
}

.topbar, .panel, .wheel-card, .modal-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(71, 20, 34, 0.9) 0%, rgba(35, 8, 16, 0.96) 100%);
  box-shadow: 0 14px 34px rgba(16, 3, 8, 0.6);
}

.topbar { padding: 14px; }
.brand { margin: 0; color: var(--accent); font-size: 11px; font-weight: 700; letter-spacing: 1.4px; }
.topbar h1 { margin: 4px 0; font-size: 28px; }
.sub { margin: 0; color: var(--muted); font-size: 13px; }

.content { display: flex; flex-direction: column; gap: 10px; }

.state-banner {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 11px;
  background: rgba(53, 16, 29, 0.85);
}
.state-banner p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}
.state-banner.is-error {
  border-color: rgba(255, 138, 138, 0.6);
}
.state-banner.is-error p {
  color: #ffd2d2;
}
.state-banner.is-loading p {
  color: #ffe2b0;
}

.wheel-card { padding: 14px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.wheel {
  --wheel-rotation: 0deg;
  width: min(72vw, 320px);
  height: min(72vw, 320px);
  border-radius: 50%;
  border: 4px solid rgba(255, 227, 168, 0.55);
  position: relative;
  background:
    conic-gradient(from 0deg,
      #7b1028 0deg 45deg,
      #b63d2a 45deg 90deg,
      #8a1730 90deg 135deg,
      #cf6d2e 135deg 180deg,
      #7b1028 180deg 225deg,
      #b63d2a 225deg 270deg,
      #8a1730 270deg 315deg,
      #cf6d2e 315deg 360deg
    );
  overflow: hidden;
  transition: transform 1.7s cubic-bezier(.1,.75,.15,1);
  box-shadow: 0 0 0 6px rgba(255, 191, 102, 0.12), 0 0 34px var(--red-glow);
}

.wheel::before {
  content: "";
  position: absolute;
  top: -14px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 12px solid transparent;
  border-right: 12px solid transparent;
  border-top: 20px solid var(--accent);
  z-index: 3;
}

.wheel-sectors {
  position: absolute;
  inset: 12px;
  border-radius: 50%;
  pointer-events: none;
}

.wheel-label {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 110px;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  color: #ffefdc;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
  transform-origin: center center;
}

.wheel-icon {
  display: block;
  font-size: 17px;
  margin-bottom: 4px;
}

.wheel-icon-img {
  width: 28px;
  height: 28px;
  object-fit: cover;
  border-radius: 50%;
  border: 1px solid rgba(255, 221, 166, 0.8);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
  margin-bottom: 4px;
}

.wheel-text {
  display: inline-block;
  max-width: 100%;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(18, 4, 8, 0.58);
  border: 1px solid rgba(255, 214, 145, 0.24);
  line-height: 1.25;
}

.wheel-text-muted {
  opacity: 0.7;
  border-color: rgba(255, 175, 175, 0.35);
  background: rgba(44, 17, 23, 0.75);
}

.wheel-chip {
  display: inline-block;
  margin-top: 3px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10px;
  background: rgba(84, 27, 40, 0.9);
  border: 1px solid rgba(255, 196, 162, 0.44);
  color: #ffd7c8;
}

.wheel-center {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  width: 84px;
  height: 84px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  background: radial-gradient(circle at 30% 20%, #ffdb97 0%, #b77921 100%);
  color: #4a1908;
  border: 2px solid rgba(255, 234, 190, 0.8);
  z-index: 2;
}

.meta { margin: 0; color: var(--muted); font-size: 13px; text-align: center; }

.cta-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
}

.btn {
  border: 1px solid var(--border);
  border-radius: 9px;
  background: rgba(89, 31, 45, 0.9);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  padding: 10px 14px;
  cursor: pointer;
}
.btn-primary {
  background: linear-gradient(180deg, #ffdb8d 0%, #c4862a 100%);
  color: #502007;
}
.btn:disabled { opacity: 0.5; }
.btn:disabled {
  cursor: not-allowed;
  filter: grayscale(0.1);
}

.panel { padding: 12px; }
.panel h2 { margin: 0 0 8px; font-size: 18px; }
.list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.list li {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(53, 16, 29, 0.9);
  padding: 10px;
  font-size: 13px;
  line-height: 1.45;
}

.history-badge {
  display: inline-block;
  margin-top: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 205, 117, 0.45);
  color: #ffd993;
  font-size: 11px;
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.history-head strong {
  font-size: 14px;
}

.history-date {
  font-size: 11px;
  color: var(--muted);
}

.history-meta {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.history-code {
  margin: 6px 0 0;
  display: inline-block;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px dashed rgba(255, 214, 140, 0.5);
  background: rgba(31, 9, 15, 0.76);
  color: #ffe7bc;
  font-weight: 700;
  font-size: 12px;
}

.conditions-grid {
  display: grid;
  gap: 8px;
}

.condition-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(53, 16, 29, 0.9);
  padding: 10px;
}

.condition-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.condition-item strong {
  display: block;
  margin-top: 4px;
  font-size: 13px;
  line-height: 1.4;
}

.panel-actions {
  margin-top: 10px;
  display: flex;
  justify-content: flex-end;
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(255, 255, 255, 0.22);
  border-top-color: #7fb2ff;
  border-radius: 50%;
  margin: 0 auto 10px;
  animation: spin 1s linear infinite;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 8, 22, 0.68);
  display: grid;
  place-items: center;
  z-index: 60;
  padding: 16px;
}
.modal-card {
  width: 100%;
  max-width: 360px;
  padding: 14px;
}
.result-type {
  margin: 0;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.4px;
}
.modal-card h3 { margin: 0; }
.modal-card p { margin: 8px 0 12px; color: var(--muted); line-height: 1.45; }
.modal-card h3 {
  display: flex;
  align-items: center;
  gap: 8px;
}
.modal-card small {
  display: block;
  margin-top: 4px;
  color: #e5c8b1;
}
.result-icon-img {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid rgba(255, 230, 170, 0.85);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.34);
}
.result-code {
  margin: 0 0 10px !important;
  color: #ffebb9 !important;
  background: rgba(20, 7, 12, 0.68);
  border: 1px solid rgba(255, 200, 118, 0.4);
  border-radius: 8px;
  padding: 8px;
  font-weight: 700;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.is-hidden { display: none !important; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 420px) {
  .cta-row { grid-template-columns: 1fr; }
}
