:root {
  --bg: #e0e5ec;
  --card: #e0e5ec;
  --text: #2d3436;
  --text-s: #7f8c8d;
  --accent: #6c5ce7;
  --lu: #e17055;
  --no-lu: #00b894;
  --r-card: 24px;
  --r-pill: 50px;
  --font: -apple-system,BlinkMacSystemFont,"SF Pro Display","SF Pro Text","Helvetica Neue",Arial,sans-serif;

  --sh-dark: #b8bec7;
  --sh-light: #ffffff;
  --neo-out: 6px 6px 14px var(--sh-dark), -6px -6px 14px var(--sh-light);
  --neo-out-sm: 3px 3px 8px var(--sh-dark), -3px -3px 8px var(--sh-light);
  --neo-in: inset 4px 4px 10px var(--sh-dark), inset -4px -4px 10px var(--sh-light);
  --neo-in-sm: inset 2px 2px 5px var(--sh-dark), inset -2px -2px 5px var(--sh-light);
  --neo-flat: none;
  --divider: rgba(0,0,0,0.06);
  --fill: #d5dbe3;
}

@media (prefers-color-scheme:dark) {
  :root {
    --bg: #2d2d32;
    --card: #2d2d32;
    --text: #e8e8e8;
    --text-s: #8e8e93;
    --accent: #a29bfe;
    --lu: #ff7675;
    --no-lu: #55efc4;

    --sh-dark: #232328;
    --sh-light: #37373c;
    --neo-out: 6px 6px 14px var(--sh-dark), -6px -6px 14px var(--sh-light);
    --neo-out-sm: 3px 3px 8px var(--sh-dark), -3px -3px 8px var(--sh-light);
    --neo-in: inset 4px 4px 10px var(--sh-dark), inset -4px -4px 10px var(--sh-light);
    --neo-in-sm: inset 2px 2px 5px var(--sh-dark), inset -2px -2px 5px var(--sh-light);
    --divider: rgba(255,255,255,0.06);
    --fill: #35353a;
  }
}

*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}

body{
  margin:0;font-family:var(--font);background:var(--bg);color:var(--text);
  line-height:1.5;-webkit-font-smoothing:antialiased;min-height:100vh;
  display:flex;flex-direction:column;transition:background .3s,color .3s;
}

button,.spin-btn,.settings-btn,.choice-btn,.mode-btn,.calendar-cell,.btn-primary,.btn-secondary{
  -webkit-user-select:none;user-select:none;
}
img,canvas{-webkit-user-drag:none;user-drag:none;pointer-events:auto}
input[type="text"],input[type="number"],textarea{-webkit-user-select:text;user-select:text}
.update-content,.notification-message,.setting-hint,.stat-number,.stat-label,.result-text,.footer-content{
  -webkit-user-select:text;user-select:text;
}

/* ── AppBar ── */
.app-bar{
  height:88px;background:var(--bg);display:flex;align-items:center;
  position:sticky;top:0;z-index:100;padding:0 20px;
  border-bottom:none;
  box-shadow:0 2px 8px var(--sh-dark);
}
.app-bar__content{
  width:100%;max-width:800px;margin:0 auto;display:flex;
  justify-content:center;align-items:center;position:relative;
}
.title{font-size:34px;font-weight:700;letter-spacing:-.5px;margin:0;color:var(--text)}
.settings-btn{
  position:absolute;right:0;background:var(--bg);border:none;width:42px;height:42px;
  border-radius:50%;display:flex;align-items:center;justify-content:center;
  color:var(--accent);cursor:pointer;
  box-shadow:var(--neo-out-sm);
  transition:box-shadow .18s ease,transform .18s ease;
}
.settings-btn:hover{
  box-shadow:8px 8px 18px var(--sh-dark),-8px -8px 18px var(--sh-light);
  transform:translateY(-1px);
}
.settings-btn:active{
  box-shadow:var(--neo-in-sm);
  transform:translateY(0);
}
.settings-btn svg{width:20px;height:20px}

@media(max-width:600px){
  .app-bar{height:64px}
  .title{font-size:28px}
}

/* ── Main ── */
main{flex:1;max-width:800px;margin:0 auto;width:100%;padding:20px}

/* ── Shared Card ── */
.roulette-card,.stats-card,.calendar-card,.chart-card{
  background:var(--card);border-radius:var(--r-card);
  box-shadow:var(--neo-out);
  padding:24px;margin-bottom:28px;
  border:1px solid rgba(255,255,255,0.06);
  transition:box-shadow .2s ease;
}

/* ── Roulette ── */
.roulette-section{display:flex;flex-direction:column;align-items:center}
.roulette-card{
  width:100%;max-width:500px;display:flex;flex-direction:column;align-items:center;position:relative;
  padding:32px 24px;
}
.roulette-container{position:relative;display:flex;align-items:center;justify-content:center}
.roulette-container.charging{animation:charge .3s infinite}
@keyframes charge{
  0%{transform:translate(1px,1px)}
  25%{transform:translate(-1px,-1px)}
  50%{transform:translate(-1px,1px)}
  75%{transform:translate(1px,-1px)}
  100%{transform:translate(1px,1px)}
}
#rouletteCanvas{
  max-width:100%;height:auto;
  filter:drop-shadow(4px 4px 10px var(--sh-dark)) drop-shadow(-4px -4px 10px var(--sh-light));
}
@media(max-width:600px){#rouletteCanvas{width:280px;height:280px}}

.roulette-pointer{
  position:absolute;top:-10px;left:50%;transform:translateX(-50%);
  width:0;height:0;border-left:12px solid transparent;border-right:12px solid transparent;
  border-top:24px solid var(--text);z-index:10;
  filter:drop-shadow(0 2px 4px var(--sh-dark));
}

.spin-btn{
  margin-top:24px;width:100%;max-width:240px;height:54px;
  background:var(--accent);color:#fff;border:none;border-radius:var(--r-pill);
  font-size:18px;font-weight:600;cursor:pointer;
  box-shadow:4px 4px 12px var(--sh-dark),-2px -2px 8px var(--sh-light),inset 0 1px 0 rgba(255,255,255,0.2);
  transition:box-shadow .18s ease,transform .18s ease;
}
.spin-btn:hover{
  box-shadow:6px 6px 16px var(--sh-dark),-4px -4px 12px var(--sh-light),inset 0 1px 0 rgba(255,255,255,0.25);
  transform:translateY(-2px);
}
.spin-btn:active{
  box-shadow:inset 3px 3px 8px rgba(0,0,0,0.25),inset -2px -2px 6px rgba(255,255,255,0.1);
  transform:translateY(0);
}
.spin-btn:disabled{opacity:.4;cursor:not-allowed;box-shadow:var(--neo-flat);transform:none}
@media(max-width:600px){.spin-btn{max-width:200px;height:48px;font-size:16px}}

.tooltip{
  position:absolute;bottom:-36px;background:rgba(0,0,0,.65);color:#fff;
  padding:6px 14px;border-radius:12px;font-size:13px;opacity:0;transition:opacity .3s;white-space:nowrap;
  backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px);
}
.tooltip.show{opacity:1}

/* ── Result ── */
.result-display{
  position:absolute;top:50%;left:50%;transform:translate(-50%,-50%) scale(.9);
  width:90%;max-width:320px;background:var(--card);border-radius:var(--r-card);
  padding:30px;text-align:center;
  box-shadow:10px 10px 30px var(--sh-dark),-10px -10px 30px var(--sh-light);
  z-index:200;opacity:0;
  transition:transform .22s cubic-bezier(.34,1.56,.64,1),opacity .22s;
}
.result-display.show{opacity:1;transform:translate(-50%,-50%) scale(1)}

body.result-lu{animation:pulse-bg 2s infinite alternate}
@keyframes pulse-bg{
  from{background:var(--bg)}
  to{background:#f0d5d0}
}
@media(prefers-color-scheme:dark){
  @keyframes pulse-bg{from{background:var(--bg)}to{background:#3a2828}}
}

.result-icon{font-size:56px;margin-bottom:12px}
.result-svg{width:64px;height:64px;display:block;margin:0 auto}
.result-text{font-size:22px;font-weight:700;margin-bottom:20px}
.result-text.success{color:var(--lu)}
.result-text.failure{color:var(--no-lu)}
.pity-notice{font-size:14px;color:var(--text-s);margin-bottom:12px;font-style:italic}
.result-choice{margin:16px 0}
.result-choice p{font-size:16px;margin-bottom:14px;color:var(--text-s)}

.choice-buttons,.result-actions{display:flex;gap:12px;justify-content:center}
.choice-btn,.share-result-btn,.confirm-result-btn{
  flex:1;height:46px;border-radius:14px;border:none;font-size:16px;font-weight:600;cursor:pointer;
  transition:box-shadow .18s ease,transform .18s ease;
}
.yes-btn{
  background:var(--lu);color:#fff;
  box-shadow:3px 3px 8px var(--sh-dark),inset 0 1px 0 rgba(255,255,255,0.2);
}
.no-btn{
  background:var(--no-lu);color:#fff;
  box-shadow:3px 3px 8px var(--sh-dark),inset 0 1px 0 rgba(255,255,255,0.2);
}
.share-result-btn{
  background:var(--fill);color:var(--accent);
  box-shadow:var(--neo-out-sm);
}
.confirm-result-btn{
  background:var(--accent);color:#fff;
  box-shadow:3px 3px 8px var(--sh-dark),inset 0 1px 0 rgba(255,255,255,0.2);
}
.choice-btn:hover,.share-result-btn:hover,.confirm-result-btn:hover{
  transform:translateY(-1px);
}
.choice-btn:active,.share-result-btn:active,.confirm-result-btn:active{
  box-shadow:var(--neo-in-sm);
  transform:translateY(0);
}

.hidden{display:none!important}

/* ── Stats ── */
.stats-section{display:flex;justify-content:center;padding:0}
.stats-card{width:100%;max-width:800px}
.stats-card h3{font-size:20px;font-weight:700;margin:0 0 20px;color:var(--text)}
.stats-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:14px}
.stat-item{
  text-align:center;padding:18px 8px;border-radius:16px;
  background:var(--card);
  box-shadow:var(--neo-in);
  transition:box-shadow .18s ease;
}
.stat-number{font-size:28px;font-weight:700}
.stat-number.success{color:var(--lu)}
.stat-number.failure{color:var(--no-lu)}
.stat-number.total{color:var(--accent)}
.stat-number.rate{color:var(--accent)}
.stat-label{font-size:12px;color:var(--text-s);font-weight:500;margin-top:4px}
@media(max-width:600px){.stats-grid{grid-template-columns:repeat(2,1fr);gap:10px}}

/* ── Calendar ── */
.calendar-section{display:flex;justify-content:center;padding:0}
.calendar-card{width:100%;max-width:800px}
.calendar-toggle{display:flex;align-items:center;justify-content:space-between;cursor:pointer}
.calendar-toggle h3{font-size:20px;font-weight:700;margin:0;color:var(--text)}
.calendar-chevron{color:var(--text-s);transition:transform .3s ease}
.calendar-chevron.open{transform:rotate(180deg)}
.calendar-collapse{max-height:0;overflow:hidden;transition:max-height .35s ease}
.calendar-collapse.open{max-height:800px}
.calendar-header{display:flex;justify-content:space-between;align-items:center;margin:16px 0;font-size:18px;font-weight:700}
.calendar-header button{
  background:var(--bg);border:none;width:38px;height:38px;border-radius:50%;
  color:var(--accent);font-weight:700;font-size:16px;cursor:pointer;
  box-shadow:var(--neo-out-sm);
  transition:box-shadow .18s ease,transform .18s ease;
}
.calendar-header button:hover{
  transform:translateY(-1px);
  box-shadow:5px 5px 12px var(--sh-dark),-5px -5px 12px var(--sh-light);
}
.calendar-header button:active{
  box-shadow:var(--neo-in-sm);
  transform:translateY(0);
}
.calendar-grid{display:grid;grid-template-columns:repeat(7,1fr);gap:4px}
.calendar-cell{
  position:relative;aspect-ratio:1;display:flex;align-items:center;justify-content:center;
  font-size:14px;font-weight:500;border-radius:12px;cursor:pointer;
  transition:box-shadow .15s ease,transform .15s ease,background .15s ease;
}
.calendar-cell:hover{
  box-shadow:var(--neo-out-sm);
  transform:translateY(-1px);
}
.calendar-cell:active{
  box-shadow:var(--neo-in-sm);
  transform:translateY(0);
}
.calendar-cell--today{
  background:var(--fill);font-weight:bold;
  box-shadow:var(--neo-in-sm);
}
.calendar-weekday{font-weight:bold;color:var(--text-s);text-align:center;font-size:14px}
.calendar-dot{position:absolute;bottom:4px;left:50%;transform:translateX(-50%)}
.calendar-dot--lu{width:6px;height:6px;border-radius:50%;background:var(--lu)}
.calendar-dot--no-lu{width:6px;height:6px;border-radius:50%;background:var(--no-lu)}
.calendar-dot--empty{width:8px;height:2px;background:var(--text-s);border-radius:1px}

/* ── Chart ── */
.chart-section{display:flex;justify-content:center;padding:0}
.chart-card{width:100%;max-width:800px}
.chart-card h3{font-size:20px;font-weight:700;margin:0 0 16px;color:var(--text)}
.chart-wrap{width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch}
.chart-svg{width:100%;height:auto;display:block}
.chart-grid{stroke:var(--divider);stroke-width:1}
.chart-label-y{fill:var(--text-s);font-size:12px;text-anchor:end}
.chart-label-x{fill:var(--text-s);font-size:11px;text-anchor:middle}
.chart-line--lu,.chart-line--no-lu{fill:none;stroke-width:2.5;stroke-linecap:round;stroke-linejoin:round}
.chart-line--lu{stroke:var(--lu)}
.chart-line--no-lu{stroke:var(--no-lu)}
.chart-area--lu{fill:var(--lu);opacity:.08}
.chart-area--no-lu{fill:var(--no-lu);opacity:.08}
.chart-dot--lu{fill:var(--lu)}
.chart-dot--no-lu{fill:var(--no-lu)}
.chart-legend{display:flex;justify-content:center;gap:24px;margin-top:12px;font-size:13px;color:var(--text-s)}
.chart-legend-item{display:flex;align-items:center;gap:6px}
.chart-legend-color{width:10px;height:10px;border-radius:50%}
.chart-legend--lu{background:var(--lu)}
.chart-legend--no-lu{background:var(--no-lu)}
.chart-empty{text-align:center;color:var(--text-s);font-size:14px;padding:20px 0}

/* ── Footer ── */
.footer{padding:32px 20px;text-align:center;color:var(--text-s);font-size:13px;margin-top:auto}
.footer a{color:var(--accent);text-decoration:none;font-weight:500}

/* ── Overlay ── */
.overlay{
  position:fixed;top:0;left:0;width:100%;height:100%;
  background:rgba(0,0,0,.3);backdrop-filter:blur(6px);-webkit-backdrop-filter:blur(6px);
  z-index:150;opacity:0;transition:opacity .22s;
}
.overlay.show{opacity:1}

/* ── Dialogs ── */
.dialog{
  position:fixed;top:50%;left:50%;transform:translate(-50%,-50%) scale(.92);
  width:90%;max-width:400px;background:var(--card);border-radius:var(--r-card);
  box-shadow:12px 12px 30px var(--sh-dark),-12px -12px 30px var(--sh-light);
  padding:28px;text-align:center;
  opacity:0;transition:transform .22s cubic-bezier(.34,1.56,.64,1),opacity .22s;z-index:200;
}
.dialog.show{transform:translate(-50%,-50%) scale(1);opacity:1}
.dialog h3{font-size:22px;font-weight:700;margin:0 0 16px;color:var(--text)}
.dialog p{font-size:17px;margin-bottom:20px;color:var(--text)}
.dialog-actions{display:flex;gap:12px;margin-top:24px}

.btn-primary,.btn-secondary{
  flex:1;height:48px;border-radius:14px;border:none;font-size:17px;font-weight:600;cursor:pointer;
  transition:box-shadow .18s ease,transform .18s ease;
}
.btn-primary{
  background:var(--accent);color:#fff;
  box-shadow:3px 3px 8px var(--sh-dark),inset 0 1px 0 rgba(255,255,255,0.2);
}
.btn-secondary{
  background:var(--bg);color:var(--accent);
  box-shadow:var(--neo-out-sm);
}
.btn-primary:hover,.btn-secondary:hover{transform:translateY(-1px)}
.btn-primary:active,.btn-secondary:active{
  box-shadow:var(--neo-in-sm);
  transform:translateY(0);
}

/* ── Settings ── */
.settings-content{text-align:left;margin:16px 0}
.setting-item{margin-bottom:20px}
.setting-item label{display:block;font-size:14px;font-weight:600;margin-bottom:8px;color:var(--text)}
.setting-hint{display:block;font-size:12px;color:var(--text-s);margin-top:6px;line-height:1.4}
.setting-item input[type="number"]{
  width:100%;height:44px;border-radius:12px;border:none;
  background:var(--bg);color:var(--text);padding:0 14px;font-size:16px;font-family:var(--font);
  box-shadow:var(--neo-in-sm);
  transition:box-shadow .18s ease;
}
.setting-item input[type="number"]:focus{
  outline:none;
  box-shadow:var(--neo-in),0 0 0 2px var(--accent);
}
.setting-item input[type="range"]{
  width:100%;height:6px;border-radius:3px;
  -webkit-appearance:none;appearance:none;outline:none;margin:10px 0;
  background:var(--bg);
  box-shadow:var(--neo-in-sm);
}
.setting-item input[type="range"]::-webkit-slider-thumb{
  -webkit-appearance:none;width:26px;height:26px;background:var(--bg);
  border-radius:50%;cursor:pointer;
  box-shadow:var(--neo-out-sm);
  transition:box-shadow .18s ease;
}
.setting-item input[type="range"]::-webkit-slider-thumb:hover{
  box-shadow:5px 5px 12px var(--sh-dark),-5px -5px 12px var(--sh-light);
}
.setting-item input[type="range"]::-moz-range-thumb{
  width:26px;height:26px;background:var(--bg);border-radius:50%;border:none;
  box-shadow:var(--neo-out-sm);cursor:pointer;
}
#luProbabilityValue{
  display:inline-block;background:var(--accent);color:#fff;padding:3px 10px;
  border-radius:10px;font-size:13px;font-weight:600;margin-left:8px;min-width:36px;text-align:center;
  box-shadow:2px 2px 6px var(--sh-dark);
}

/* Segmented control */
.mode-buttons{
  display:flex;padding:3px;border-radius:14px;margin:8px 0;
  background:var(--bg);
  box-shadow:var(--neo-in-sm);
}
.mode-btn{
  flex:1;border:none;background:transparent;height:34px;border-radius:11px;
  font-size:14px;font-weight:600;color:var(--text-s);cursor:pointer;
  transition:all .2s ease;
}
.mode-btn.active{
  background:var(--bg);color:var(--text);
  box-shadow:var(--neo-out-sm);
}

.data-buttons{display:flex;gap:10px;flex-wrap:wrap}
.data-buttons button{flex:1;min-width:100px}

/* ── Notification ── */
.notification-dialog{
  position:fixed;top:50%;left:50%;transform:translate(-50%,-50%) scale(.92);
  width:270px;background:var(--card);border-radius:20px;padding:24px;
  text-align:center;
  box-shadow:10px 10px 26px var(--sh-dark),-10px -10px 26px var(--sh-light);
  z-index:250;opacity:0;transition:transform .22s cubic-bezier(.34,1.56,.64,1),opacity .22s;
}
.notification-dialog.show{opacity:1;transform:translate(-50%,-50%) scale(1)}
.notification-content{text-align:center}
.notification-icon{font-size:44px;margin-bottom:12px}
.notification-message{font-size:16px;color:var(--text);margin-bottom:20px;line-height:1.4;font-weight:500}

/* ── Update Log ── */
.update-content{text-align:left;max-height:320px;overflow-y:auto}
.update-item{margin-bottom:20px}
.update-item h4{color:var(--text);margin:0 0 10px;font-size:16px}
.update-item ul{margin:0;padding-left:20px}
.update-item li{margin-bottom:6px;line-height:1.5;font-size:14px;color:var(--text)}

/* ── History Edit ── */
.history-edit-buttons{display:flex;gap:12px;justify-content:center;margin:16px 0}
#historyEditDate{text-align:center;font-size:17px;font-weight:600;color:var(--accent);margin-bottom:16px}

@media (prefers-reduced-motion: reduce){
  .roulette-container.charging,
  body.result-lu{
    animation:none !important;
  }
  .confetti-piece{
    animation:none !important;
    transition:none !important;
  }
  .tour-spotlight{transition:opacity .3s !important}
  .tour-tooltip{transition:opacity .25s !important}
}

/* ── Tour Guide ── */
.tour-backdrop{position:fixed;inset:0;z-index:998;opacity:0;pointer-events:none;transition:opacity .3s}
.tour-backdrop.show{opacity:1;pointer-events:auto}

.tour-spotlight{
  position:fixed;z-index:999;border-radius:16px;
  box-shadow:0 0 0 9999px rgba(0,0,0,.45);
  pointer-events:none;opacity:0;
  transition:top .35s ease,left .35s ease,width .35s ease,height .35s ease,opacity .3s;
}
.tour-spotlight.show{opacity:1}

.tour-tooltip{
  position:fixed;z-index:1000;width:320px;max-width:calc(100vw - 24px);
  background:var(--card);border-radius:20px;padding:24px;
  box-shadow:var(--neo-out),0 8px 32px rgba(0,0,0,.12);
  opacity:0;transform:translateY(8px);
  transition:opacity .25s,transform .25s ease;
  pointer-events:none;
}
.tour-tooltip.show{opacity:1;transform:translateY(0);pointer-events:auto}

.tour-tooltip::before{content:'';position:absolute;width:0;height:0}
.tour-tooltip.tour-pos-bottom::before{
  top:-10px;left:50%;transform:translateX(-50%);
  border-left:10px solid transparent;border-right:10px solid transparent;border-bottom:10px solid var(--card);
}
.tour-tooltip.tour-pos-top::before{
  bottom:-10px;left:50%;transform:translateX(-50%);
  border-left:10px solid transparent;border-right:10px solid transparent;border-top:10px solid var(--card);
}

.tour-close{
  position:absolute;top:12px;right:14px;background:none;border:none;
  font-size:22px;color:var(--text-s);cursor:pointer;line-height:1;padding:2px 6px;
  border-radius:8px;transition:color .15s;
}
.tour-close:hover{color:var(--text)}

.tour-header{font-size:18px;font-weight:700;color:var(--text);margin-bottom:8px;padding-right:24px}
.tour-body{font-size:14px;color:var(--text-s);line-height:1.5;margin-bottom:20px}
.tour-footer{display:flex;align-items:center;justify-content:space-between}
.tour-dots{display:flex;gap:6px}

.tour-dot{
  width:8px;height:8px;border-radius:50%;background:var(--fill);
  box-shadow:var(--neo-in-sm);transition:background .2s,box-shadow .2s;
}
.tour-dot.active{background:var(--accent);box-shadow:0 0 6px var(--accent)}

.tour-nav{display:flex;gap:8px}
.tour-btn{
  height:36px;padding:0 18px;border:none;border-radius:12px;
  font-size:14px;font-weight:600;cursor:pointer;
  transition:box-shadow .18s ease,transform .18s ease;
}
.tour-prev{background:var(--bg);color:var(--text-s);box-shadow:var(--neo-out-sm)}
.tour-prev:hover{transform:translateY(-1px)}
.tour-prev:active{box-shadow:var(--neo-in-sm);transform:translateY(0)}
.tour-next{
  background:var(--accent);color:#fff;
  box-shadow:3px 3px 8px var(--sh-dark),inset 0 1px 0 rgba(255,255,255,.2);
}
.tour-next:hover{transform:translateY(-1px)}
.tour-next:active{box-shadow:inset 2px 2px 5px rgba(0,0,0,.2);transform:translateY(0)}

/* ── Mobile ── */
@media(max-width:600px){
  .dialog{width:92%;padding:24px}
  .result-actions{flex-direction:column;gap:8px}
  .data-buttons{flex-direction:column}
  .data-buttons button{flex:none}
  .notification-dialog{width:85%}
  .tour-tooltip{width:280px;padding:20px}
  .tour-header{font-size:16px}
  .tour-body{font-size:13px}
}
