:root {
  --font-main: 'Noto Sans KR', 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --bg-opacity: 0.62;
  --simple-label: #a9c2d1;
  --simple-value: #ffffff;
  --simple-pos: #4ade80;
  --simple-neg: #ef4444;
  --simple-remain: #fcd34d;
  --rate-win: #86efac;
  --rate-dealin: #fca5a5;
  --rate-furo: #7dd3fc;
  --rate-riichi: #fde047;

  --shell-bg: linear-gradient(140deg, rgba(10, 18, 34, 0.90) 0%, rgba(16, 29, 52, 0.88) 100%);
  --shell-border: rgba(56, 189, 248, 0.38);
  --shell-shadow: 0 12px 32px rgba(3, 8, 20, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  --text-main: #f8fafc;
  --text-sub: #94a3b8;
  --text-muted: #64748b;
  --pill-bg: rgba(255, 255, 255, 0.06);
  --pill-border: rgba(255, 255, 255, 0.09);
  --bar-bg: rgba(255, 255, 255, 0.10);
  --bar-fill: linear-gradient(90deg, #27c7ff 0%, #4f8cff 100%);
  --accent: #38bdf8;
  --pos: #86efac;
  --neg: #fca5a5;
  --p1: #93e2b7;
  --p2: #64a6ff;
  --p3: #bcc6d2;
  --p4: #f2a6ac;
  --live: #86efac;
}

body.theme-dark {
  --shell-bg: linear-gradient(145deg, rgba(17, 20, 27, 0.92) 0%, rgba(24, 28, 37, 0.90) 100%);
  --shell-border: rgba(255, 255, 255, 0.14);
  --bar-fill: linear-gradient(90deg, #60a5fa 0%, #a78bfa 100%);
  --accent: #93c5fd;
}

body.theme-light {
  --simple-label: #334155;
  --simple-value: #0f172a;
  --simple-pos: #059669;
  --simple-neg: #dc2626;
  --simple-remain: #b45309;
  --rate-win: #059669;
  --rate-dealin: #dc2626;
  --rate-furo: #0284c7;
  --rate-riichi: #b45309;
  --shell-bg: linear-gradient(145deg, rgba(248, 251, 255, 0.94) 0%, rgba(235, 244, 255, 0.92) 100%);
  --shell-border: rgba(14, 165, 233, 0.32);
  --shell-shadow: 0 10px 28px rgba(15, 23, 42, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.85);
  --text-main: #0f172a;
  --text-sub: #475569;
  --text-muted: #64748b;
  --pill-bg: rgba(15, 23, 42, 0.05);
  --pill-border: rgba(15, 23, 42, 0.10);
  --bar-bg: rgba(15, 23, 42, 0.10);
  --bar-fill: linear-gradient(90deg, #0284c7 0%, #2563eb 100%);
  --accent: #0284c7;
  --pos: #059669;
  --neg: #e11d48;
  --p1: #0d9488;
  --p2: #2563eb;
  --p3: #d97706;
  --p4: #dc2626;
  --live: #059669;
}

body.theme-neon {
  --shell-bg: linear-gradient(135deg, rgba(16, 8, 34, 0.92) 0%, rgba(10, 22, 46, 0.92) 100%);
  --shell-border: rgba(236, 72, 153, 0.55);
  --shell-shadow: 0 0 24px rgba(56, 189, 248, 0.25), 0 12px 30px rgba(0, 0, 0, 0.6);
  --bar-fill: linear-gradient(90deg, #f472b6 0%, #38bdf8 100%);
  --accent: #f472b6;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  font-family: var(--font-main);
  color: var(--text-main);
  overflow: hidden;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

body.bg-transparent { background: transparent !important; }
body.bg-solid { background: #0b1120; }

.overlay-root {
  padding: 10px;
  display: inline-block;
}

/* ==================== LAYOUT: SIMPLE (score-compete style, default) ==================== */
body.layout-simple .overlay-shell {
  display: inline-flex;
  flex-direction: column;
  width: min-content;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 8px;
  border: 2px solid rgba(255, 255, 255, 0.22);
  background: rgba(0, 0, 0, var(--bg-opacity));
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: none;
  text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.88);
  font-size: 21px;
  line-height: 1.3;
  overflow: visible;
}

body.layout-simple.theme-light .overlay-shell {
  background: rgba(255, 255, 255, var(--bg-opacity));
  border-color: rgba(15, 23, 42, 0.22);
  text-shadow: none;
}

body.layout-simple .overlay-shell::before {
  display: none;
}

.simple-line {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  padding: 2px 6px;
  border-radius: 6px;
  border-left: 3px solid #38bdf8;
  position: relative;
  white-space: nowrap;
  transition: background 0.35s ease, border-color 0.35s ease, transform 0.25s ease;
}

.simple-line > * {
  flex-shrink: 0;
}

.simple-line.is-legend {
  border-left-color: transparent;
  background: linear-gradient(
    90deg,
    rgba(255, 126, 179, 0.14) 0%,
    rgba(253, 224, 71, 0.10) 25%,
    rgba(110, 231, 183, 0.10) 50%,
    rgba(56, 189, 248, 0.12) 75%,
    rgba(192, 132, 252, 0.14) 100%
  );
}

.simple-line.is-legend::before {
  content: "";
  position: absolute;
  left: -3px;
  top: 0;
  bottom: 0;
  width: 3px;
  border-radius: 6px 0 0 6px;
  background: linear-gradient(
    180deg,
    #ff7eb3 0%,
    #fde047 22%,
    #6ee7b7 44%,
    #38bdf8 66%,
    #c084fc 84%,
    #ff7eb3 100%
  );
  background-size: 100% 200%;
  animation: urRainbowVert 4s linear infinite;
}

.simple-rank-legend {
  background: linear-gradient(
    90deg,
    #ff7eb3 0%,
    #fde047 20%,
    #6ee7b7 40%,
    #38bdf8 60%,
    #c084fc 80%,
    #ff7eb3 100%
  );
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  text-shadow: none;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.9)) drop-shadow(0 0 6px rgba(192, 132, 252, 0.45));
  animation: urRainbowText 3.8s linear infinite;
}

body.theme-light .simple-rank-legend {
  background: linear-gradient(
    90deg,
    #ec4899 0%,
    #eab308 20%,
    #10b981 40%,
    #0284c7 60%,
    #9333ea 80%,
    #ec4899 100%
  );
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  filter: drop-shadow(0 0 4px rgba(147, 51, 234, 0.22));
}

@keyframes urRainbowText {
  0% { background-position: 0% 50%; }
  100% { background-position: 200% 50%; }
}

@keyframes urRainbowVert {
  0% { background-position: 50% 0%; }
  100% { background-position: 50% 200%; }
}

@keyframes urRainbowBg {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.simple-line.flash-up {
  animation: simpleFlashUp 1.4s ease-out;
}

.simple-line.flash-down {
  animation: simpleFlashDown 1.4s ease-out;
}

@keyframes simpleFlashUp {
  0% { background: rgba(74, 222, 128, 0.34); transform: translateY(-1px); }
  100% { background: transparent; transform: translateY(0); }
}

@keyframes simpleFlashDown {
  0% { background: rgba(239, 68, 68, 0.34); transform: translateX(-2px); }
  35% { transform: translateX(2px); }
  100% { background: transparent; transform: translateX(0); }
}

.simple-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  background: #64748b;
}

.simple-dot.playing {
  background: #86efac;
  box-shadow: 0 0 5px rgba(134, 239, 172, 0.55);
}

.simple-dot.ready {
  background: #38bdf8;
  box-shadow: 0 0 6px #38bdf8;
}

.simple-name {
  font-weight: 900;
  color: var(--simple-value);
}

.simple-group {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
}

.simple-label {
  color: var(--simple-label);
  font-size: 18px;
  font-weight: 700;
}

.simple-value {
  color: var(--simple-value);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.simple-max {
  color: #94a3b8;
  font-size: 17px;
  font-weight: 700;
}

.simple-diff {
  font-size: 19px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.simple-diff.positive { color: var(--simple-pos); }
.simple-diff.negative { color: var(--simple-neg); }
.simple-diff.neutral { color: var(--simple-label); opacity: 0.78; }

.simple-remain {
  color: var(--simple-remain);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.simple-subline {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 7px 6px 0 9px;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  font-size: 19px;
  width: 100%;
  min-width: 0;
}

.simple-subline > .simple-group {
  display: flex;
  align-items: baseline;
  gap: 7px;
  width: 100%;
  min-width: 0;
}

.simple-subline .simple-label {
  flex-shrink: 0;
  white-space: nowrap;
}

.simple-seq {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  flex: 1 1 0;
  min-width: 0;
  row-gap: 4px;
  column-gap: 12px;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 1.5px;
  font-variant-numeric: tabular-nums;
}

.seq-chunk {
  display: inline-flex;
  align-items: baseline;
  white-space: nowrap;
  flex-shrink: 0;
}

.seq-digit {
  display: inline-block;
  font-weight: 900;
}

.seq-digit.r1 { color: #93e2b7; }
.seq-digit.r2 { color: #64a6ff; }
.seq-digit.r3 { color: #bcc6d2; }
.seq-digit.r4 { color: #f2a6ac; }

.simple-meta-dim {
  color: #94a3b8;
  font-size: 16px;
  font-weight: 700;
}

.simple-slash {
  color: rgba(148, 163, 184, 0.55);
  font-size: 19px;
  font-weight: 700;
}

.simple-places {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  font-size: 20px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.sp-sep {
  color: rgba(148, 163, 184, 0.45);
  font-weight: 700;
}

.simple-rates {
  display: inline-flex;
  align-items: baseline;
  gap: 12px;
}

.rate-win { color: var(--rate-win); }
.rate-dealin { color: var(--rate-dealin); }
.rate-furo { color: var(--rate-furo); }
.rate-riichi { color: var(--rate-riichi); }

.floating-delta {
  position: absolute;
  right: 120px;
  top: -12px;
  font-size: 16px;
  font-weight: 900;
  padding: 2px 7px;
  border-radius: 5px;
  pointer-events: none;
  animation: floatDeltaSimple 2.0s ease-out forwards;
}

.floating-delta.up {
  color: #4ade80;
  background: rgba(6, 78, 59, 0.92);
  border: 1px solid rgba(74, 222, 128, 0.6);
}

.floating-delta.down {
  color: #f87171;
  background: rgba(127, 29, 29, 0.92);
  border: 1px solid rgba(248, 113, 113, 0.6);
}

@keyframes floatDeltaSimple {
  0% { opacity: 0; transform: translateY(6px); }
  20% { opacity: 1; transform: translateY(-2px); }
  80% { opacity: 1; transform: translateY(-10px); }
  100% { opacity: 0; transform: translateY(-16px); }
}

/* ==================== LAYOUTS: CARD / BAR / VERTICAL / FULL ==================== */
body:not(.layout-simple) .overlay-root {
  width: 100%;
  padding: 8px;
}

.overlay-shell {
  position: relative;
  background: var(--shell-bg);
  border: 1.5px solid var(--shell-border);
  border-radius: 16px;
  box-shadow: var(--shell-shadow);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: 14px 16px;
  overflow: hidden;
}

.overlay-shell::before {
  content: "";
  position: absolute;
  top: -36px;
  right: -28px;
  width: 110px;
  height: 110px;
  background: radial-gradient(circle, rgba(56, 189, 248, 0.16) 0%, transparent 70%);
  pointer-events: none;
}

.empty-msg {
  font-size: 16px;
  font-weight: 700;
  color: var(--simple-label);
  text-align: center;
  padding: 8px 10px;
  white-space: nowrap;
}

.ov-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.ov-identity {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.rank-emblem {
  flex-shrink: 0;
  min-width: 54px;
  height: 44px;
  padding: 0 10px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 19px;
  line-height: 1;
  color: #07101e;
  letter-spacing: -0.4px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.rank-emblem.legend {
  font-size: 15px;
  background: linear-gradient(
    135deg,
    #ff7eb3 0%,
    #fde047 22%,
    #6ee7b7 44%,
    #38bdf8 66%,
    #c084fc 84%,
    #ff7eb3 100%
  );
  background-size: 260% 260%;
  color: #07101e;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
  box-shadow:
    0 0 14px rgba(192, 132, 252, 0.45),
    0 0 22px rgba(56, 189, 248, 0.25),
    0 4px 14px rgba(0, 0, 0, 0.30),
    inset 0 1px 0 rgba(255, 255, 255, 0.78);
  animation: urRainbowBg 5s ease infinite;
}

.rank-emblem-sub {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.6px;
  opacity: 0.85;
  margin-top: 2px;
  text-transform: uppercase;
}

.ov-name-block {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.ov-name-line {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.ov-nickname {
  font-size: 17px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 190px;
}

.mode-chip {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--pill-bg);
  border: 1px solid var(--pill-border);
  color: var(--text-sub);
  letter-spacing: 0.3px;
}

.live-chip {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  color: var(--live);
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(52, 211, 153, 0.14);
  border: 1px solid rgba(52, 211, 153, 0.35);
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--live);
  box-shadow: 0 0 5px rgba(134, 239, 172, 0.55);
}

@keyframes livePulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.8); }
}

.ov-subline {
  font-size: 12px;
  color: var(--text-sub);
  display: flex;
  align-items: center;
  gap: 8px;
}

.ov-delta-box { flex-shrink: 0; text-align: right; }

.ov-delta-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-sub);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.ov-delta-value {
  font-size: 24px;
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
}

.pt-pos { color: var(--pos); }
.pt-neg { color: var(--neg); }
.pt-zero { color: var(--text-sub); }

.ov-progress { margin-top: 11px; }

.ov-progress-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
  margin-bottom: 5px;
  font-variant-numeric: tabular-nums;
}

.ov-pt-now { font-weight: 800; color: var(--text-main); }
.ov-pt-now span { font-weight: 600; color: var(--text-sub); }
.ov-pt-remain { font-size: 11px; color: var(--text-sub); font-weight: 600; }

.progress-track {
  width: 100%;
  height: 8px;
  background: var(--bar-bg);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--bar-fill);
  border-radius: 999px;
  transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

.ov-stats-row {
  margin-top: 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.placement-pills {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.place-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border-radius: 8px;
  background: var(--pill-bg);
  border: 1px solid var(--pill-border);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.place-pill .p-rank { font-size: 11px; font-weight: 800; }
.p-c1 { color: var(--p1); }
.p-c2 { color: var(--p2); }
.p-c3 { color: var(--p3); }
.p-c4 { color: var(--p4); }

.avg-pill {
  font-size: 12px;
  font-weight: 800;
  color: var(--accent);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.ov-rates-row {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.rate-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 7px;
  border-radius: 7px;
  background: var(--pill-bg);
  border: 1px solid var(--pill-border);
  font-size: 11px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.rate-pill .rp-label {
  color: var(--text-sub);
  font-weight: 700;
}

body.layout-bar .ov-rates-row {
  margin-top: 0;
  flex-wrap: nowrap;
}

body.layout-vertical .ov-rates-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
}

body.layout-vertical .rate-pill {
  justify-content: space-between;
}

.ov-recent-row {
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid var(--pill-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.recent-label { font-size: 11px; font-weight: 700; color: var(--text-sub); flex-shrink: 0; }

.recent-badges {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: nowrap;
  overflow: hidden;
}

.r-badge {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  border: 1px solid transparent;
  flex-shrink: 0;
}

.r-badge.newest { transform: scale(1.06); box-shadow: 0 0 10px rgba(56, 189, 248, 0.35); }
.r-badge.r1 { background: rgba(147, 226, 183, 0.18); color: var(--p1); border-color: rgba(147, 226, 183, 0.45); }
.r-badge.r2 { background: rgba(100, 166, 255, 0.20); color: var(--p2); border-color: rgba(100, 166, 255, 0.50); }
.r-badge.r3 { background: rgba(188, 198, 210, 0.18); color: var(--p3); border-color: rgba(188, 198, 210, 0.42); }
.r-badge.r4 { background: rgba(242, 166, 172, 0.18); color: var(--p4); border-color: rgba(242, 166, 172, 0.45); }

.ov-graph {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--pill-border);
  height: 82px;
}

.ov-graph svg { width: 100%; height: 100%; overflow: visible; }

/* BAR */
body.layout-bar .overlay-shell { padding: 9px 14px; border-radius: 14px; }
.bar-wrap { display: flex; align-items: center; gap: 14px; flex-wrap: nowrap; }
.bar-divider { width: 1px; height: 30px; background: var(--pill-border); flex-shrink: 0; }
.bar-pt-block { min-width: 138px; display: flex; flex-direction: column; gap: 4px; }
.bar-pt-top { display: flex; justify-content: space-between; align-items: baseline; font-size: 12px; font-weight: 800; font-variant-numeric: tabular-nums; }
.bar-pt-top span { font-size: 11px; color: var(--text-sub); font-weight: 600; }
.bar-delta { font-size: 20px; font-weight: 900; font-variant-numeric: tabular-nums; white-space: nowrap; }
body.layout-bar .rank-emblem { min-width: 44px; height: 36px; font-size: 16px; border-radius: 10px; }
body.layout-bar .rank-emblem.legend { font-size: 14px; }
body.layout-bar .ov-nickname { font-size: 15px; max-width: 140px; }

/* VERTICAL */
body.layout-vertical .overlay-shell { padding: 14px; }
body.layout-vertical .ov-header { flex-direction: column; align-items: flex-start; gap: 10px; }
body.layout-vertical .ov-delta-box {
  width: 100%; display: flex; align-items: baseline; justify-content: space-between;
  padding: 8px 10px; border-radius: 10px; background: var(--pill-bg); border: 1px solid var(--pill-border);
}
body.layout-vertical .ov-stats-row { flex-direction: column; align-items: stretch; gap: 8px; }
body.layout-vertical .placement-pills { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
body.layout-vertical .place-pill { justify-content: space-between; }
body.layout-vertical .avg-pill { text-align: center; padding: 4px 8px; border-radius: 8px; background: var(--pill-bg); }
body.layout-vertical .ov-recent-row { flex-direction: column; align-items: flex-start; gap: 6px; }
body.layout-vertical .recent-badges { flex-wrap: wrap; }
