:root{
  --pageBg:#002D89;
  --pageBgDeep:#001f63;

  --panel:rgba(255,255,255,0.08);
  --panelStrong:rgba(255,255,255,0.12);
  --panelSolid:#123b9a;
  --line:rgba(232,236,255,0.16);

  --text:#e8ecff;
  --muted:rgba(232,236,255,0.72);

  --accent-yellow:#FFFF00;
  --accent-orange:#ED7D31;
  --accent-red:#FF0000;
  --accent-green:#00B050;
  --accent-cyan:#00B0F0;
  --accent-purple:#7030A0;

  --accent:var(--accent-cyan);
  --accent-soft:rgba(0,176,240,0.16);

  --btnBg:#7aa2ff;
  --btnText:#0b1020;
  --btnRadius:12px;

  --radius:14px;
  --shadow:0 10px 24px rgba(0,0,0,0.28);

  --week-row-h:56px;
  --week-dow-h:30px;

  --mono:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --sans:ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;

  --afds-header-h:68px;
}

*{ box-sizing:border-box; }

html, body{ height:100%; }

body{
  margin:0;
  font-family:var(--sans);
  color:var(--text);
  background:
    radial-gradient(circle at top, rgba(255,255,255,0.06), transparent 28%),
    linear-gradient(180deg, var(--pageBg) 0%, var(--pageBgDeep) 100%);
  overflow:hidden;
}

.app{
  height:100vh;
  display:flex;
  flex-direction:column;
}

.topbar{
  min-height:64px;
  display:grid;
  grid-template-columns:auto 1fr auto;
  align-items:center;
  gap:16px;
  padding:12px 16px;
  border-bottom:1px solid var(--line);
  background:rgba(0,45,137,0.72);
  backdrop-filter:blur(8px);
  flex:0 0 auto;
}

.topbar-left,
.topbar-right{
  display:flex;
  align-items:center;
}

.topbar-center{
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  text-align:center;
  min-width:0;
}

.brand{
  font-weight:700;
  letter-spacing:0.2px;
  font-size:clamp(18px, 2.2vw, 24px);
  color:var(--text);
}

.subbrand{
  margin-top:2px;
  font-size:12px;
  color:var(--muted);
  letter-spacing:0.08em;
  text-transform:uppercase;
}

.badge{
  font-size:12px;
  padding:6px 10px;
  border:1px solid var(--line);
  border-radius:999px;
  color:var(--text);
  background:rgba(255,255,255,0.08);
}

.layout{
  flex:1;
  display:flex;
  gap:12px;
  padding:12px;
  align-items:stretch;
  position:relative;
  min-height:0;
}

.panel{
  background:var(--panel);
  border:1px solid var(--line);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  overflow:hidden;
  min-height:0;
  backdrop-filter:blur(6px);
}

.panel-inner{
  padding:14px;
  height:100%;
  overflow:auto;
}

.panel.left{ width:320px; }
.panel.right{ width:320px; }

.center{
  flex:1;
  min-width:560px;
  min-height:0;
  display:flex;
  flex-direction:column;
  gap:10px;
}

.cal-header{
  background:var(--panel);
  border:1px solid var(--line);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  padding:12px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  flex:0 0 auto;
  backdrop-filter:blur(6px);
  position:relative;
  z-index:30;
  overflow:visible;
}

.nav{
  display:flex;
  align-items:center;
  gap:10px;
}

.title{
  font-weight:600;
  min-width:240px;
}

.controls{
  display:flex;
  gap:10px;
  align-items:flex-end;
  flex-wrap:wrap;
  justify-content:flex-end;
  position:relative;
  z-index:31;
}

.control{
  display:flex;
  flex-direction:column;
  gap:6px;
  position:relative;
}

.control label{
  font-size:12px;
  color:var(--muted);
}

.control select,
.control input,
.tzselect{
  height:34px;
  border:1px solid var(--line);
  border-radius:10px;
  padding:0 10px;
  background:rgba(255,255,255,0.10);
  color:var(--text);
}

.control select option,
.jump-row select option,
#displayTZ option,
.tzselect option{
  color:#111318;
  background:#ffffff;
}

.jump-row{
  display:flex;
  gap:6px;
  align-items:center;
}

.jump-row select{ width:110px; }
.jump-row input{
  width:140px;
  font-family:var(--mono);
}

.btn{
  height:34px;
  padding:0 12px;
  border:none;
  border-radius:var(--btnRadius);
  background:var(--btnBg);
  color:var(--btnText);
  cursor:pointer;
  box-shadow:var(--shadow);
  text-decoration:none;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  font-weight:600;
}

.btn:hover{ filter:brightness(1.05); }

.btn:focus-visible{
  outline:2px solid #fff;
  outline-offset:2px;
}

.iconbtn{
  width:34px;
  height:34px;
  border:none;
  border-radius:var(--btnRadius);
  background:var(--btnBg);
  color:var(--btnText);
  cursor:pointer;
  font-size:18px;
  line-height:32px;
  box-shadow:var(--shadow);
}

.iconbtn:hover{ filter:brightness(1.05); }

.dropdown{
  position:absolute;
  margin-top:6px;
  right:12px;
  top:56px;
  width:180px;
  padding:10px;
  border:1px solid var(--line);
  border-radius:12px;
  background:rgba(0,31,99,0.96);
  color:var(--text);
  box-shadow:var(--shadow);
  z-index:200;
  backdrop-filter:blur(8px);
}

.cal-surface{
  z-index:1;
}

.chk{
  display:flex;
  gap:8px;
  align-items:center;
  font-size:14px;
}

.small{ font-size:12px; }
.muted{ color:var(--muted); }

/* Central scroll container */
.cal-surface{
  flex:1;
  min-height:0;
  background:var(--panel);
  border:1px solid var(--line);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  position:relative;
  overflow:auto;
  overscroll-behavior:contain;
  backdrop-filter:blur(6px);
}

/* Month + Week wrappers */
.month,
.week{
  position:relative;
  display:flex;
  flex-direction:column;
}

/* Sticky weekday rows */
.dow{
  position:sticky;
  top:0;
  z-index:20;
  display:grid;
  grid-template-columns:repeat(7, 1fr);
  border-bottom:1px solid var(--line);
  background:rgba(0,31,99,0.92);
  backdrop-filter:blur(6px);
}

.dow div{
  padding:10px 10px;
  font-size:12px;
  color:var(--muted);
  border-right:1px solid var(--line);
}
.dow div:last-child{ border-right:none; }

.week-dow{
  position:sticky;
  top:0;
  z-index:20;
  display:grid;
  grid-template-columns:70px repeat(7, 1fr);
  border-bottom:1px solid var(--line);
  background:rgba(0,31,99,0.92);
  backdrop-filter:blur(6px);
}

.week-dow-spacer{
  border-right:1px solid var(--line);
  background:rgba(0,31,99,0.92);
}

.week-dow-cell{
  padding:10px 10px;
  border-right:1px solid var(--line);
  background:rgba(0,31,99,0.92);
}
.week-dow-cell:last-child{ border-right:0; }

.week-dow-main{
  font-size:12px;
  color:var(--text);
  white-space:normal;
  line-height:1.2;
}
.week-dow-sub{
  margin-top:2px;
  font-size:11px;
  color:var(--muted);
  opacity:0.9;
}

/* Month grid */
.month-bars{
  display:grid;
  grid-template-columns:repeat(7, 1fr);
  grid-auto-rows:22px;
  gap:2px 6px;
  padding:6px 6px 0 6px;
  position:relative;
  z-index:1;
}

.week{
  border-bottom:1px solid var(--line);
}
.week:last-child{ border-bottom:none; }

.week-bars{
  display:grid;
  grid-template-columns:70px repeat(7, 1fr);
  grid-auto-rows:22px;
  row-gap:2px;
  column-gap:1px;
  padding:6px 0 0 0;
  position:sticky;
  top:var(--week-dow-h);
  z-index:19;
  border-bottom:1px solid var(--line);
}

/* Hour grid */
.week-grid{
  display:grid;
  grid-template-columns:70px repeat(7, 1fr);
  position:relative;
  z-index:1;
}

.time-label{
  position:relative;
  height:var(--week-row-h);
  border-right:1px solid var(--line);
  border-bottom:1px solid var(--line);
  background:rgba(0,31,99,0.55);
  font-family:var(--mono);
  font-size:12px;
  color:var(--muted);
}

.time-label .main{
  position:absolute;
  top:6px;
  left:8px;
}

.time-label .ov{
  position:absolute;
  bottom:6px;
  right:8px;
  font-size:11px;
  color:var(--muted);
  opacity:0.9;
}

.week-cell{
  height:var(--week-row-h);
  position:relative;
  border-right:1px solid var(--line);
  border-bottom:1px solid var(--line);
  background:rgba(255,255,255,0.03);
}
.week-cell:nth-child(8n){ border-right:0; }

.bar{
  border-radius:8px;
  padding:3px 8px;
  font-size:12px;
  font-weight:700;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  border:none;
  box-shadow:0 2px 8px rgba(0,0,0,0.18);
}

.bar.yellow{
  background:#FFFF00;
  color:#2c2a00;
}

.bar.orange{
  background:#ED7D31;
  color:#2a1303;
}

.bar.red{
  background:#FF0000;
  color:#fff1f1;
}

.bar.green{
  background:#00B050;
  color:#041d0d;
}

.bar.blue{
  background:#00B0F0;
  color:#081225;
}

.bar.purple{
  background:#7030A0;
  color:#f5ecff;
}

.bar.supermonth-blue{
  background:#00B0F0;
  color:#081225;
}

.bar.supermonth-purple{
  background:#7030A0;
  color:#f5ecff;
}

.bar:hover{
  border-color:rgba(255,255,255,0.24);
}

/* Month day cells */
.week-days{
  display:grid;
  grid-template-columns:repeat(7, 1fr);
  position:relative;
  z-index:1;
}

.day{
  min-height:92px;
  border-right:1px solid var(--line);
  padding:8px 8px 6px 8px;
  position:relative;
  background:transparent;
}
.day:last-child{ border-right:none; }

.day .sd{
  font-family:var(--mono);
  font-size:12px;
  color:var(--text);
  opacity:0.92;
  white-space:normal;
  line-height:1.2;
}

.lunar-markers{
  margin-top:6px;
  display:flex;
  gap:6px;
  align-items:center;
  min-height:16px;
}

.lunar-marker{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:16px;
  height:16px;
  border-radius:50%;
  font-size:12px;
  line-height:1;
  color:var(--text);
  background:rgba(255,255,255,0.08);
  border:1px solid rgba(255,255,255,0.14);
}

.lunar-marker.lunar-new{
  color:#111318;
  background:rgba(232,236,255,0.92);
}

.lunar-marker.lunar-full{
  background:rgba(255,255,255,0.18);
}

.day .g{
  font-size:11px;
  color:var(--muted);
  margin-top:2px;
}

.day .more{
  margin-top:6px;
  font-size:12px;
  color:var(--accent-cyan);
  cursor:pointer;
}

.day:hover{
  outline:2px solid rgba(122,162,255,0.35);
  outline-offset:-2px;
}

.day.today::after{
  content:"";
  position:absolute;
  right:8px;
  top:8px;
  width:8px;
  height:8px;
  border-radius:50%;
  background:var(--accent-yellow);
  opacity:0.95;
}

.day.highlight{
  background:var(--accent-soft);
}

.day.outside{
  background:rgba(255,255,255,0.03);
  opacity:0.72;
}

.day.outside .sd{
  color:var(--muted);
}

/* Inspector */
.seoian-big{
  font-family:var(--mono);
  font-size:22px;
  font-weight:700;
  letter-spacing:0.3px;
}

.gregorian-small{
  margin-top:6px;
  font-size:13px;
  color:var(--muted);
}

.toggle{
  display:flex;
  gap:8px;
  align-items:center;
  font-size:13px;
  color:var(--muted);
  margin-top:8px;
}

.toggle-inline{
  margin-top:0;
  min-height:34px;
  padding:0 2px;
}

.control-mobile-gregorian{
  display:none;
}

.section{ margin-top:16px; }

.section-title{
  font-size:12px;
  color:var(--muted);
  margin-bottom:8px;
  text-transform:uppercase;
  letter-spacing:0.08em;
}

.list{
  display:flex;
  flex-direction:column;
  gap:6px;
}

.pill{
  padding:8px 10px;
  border:1px solid var(--line);
  border-radius:12px;
  background:rgba(255,255,255,0.08);
  color:var(--text);
  font-size:13px;
}

.eventitem{
  padding:8px 10px;
  border:1px solid var(--line);
  border-radius:12px;
  background:rgba(255,255,255,0.08);
  color:var(--text);
}

.eventitem .title{
  font-size:13px;
  font-weight:700;
  color:var(--text);
}

.eventitem .note{
  margin-top:3px;
  font-size:12px;
  color:var(--muted);
}

.eventitem.lunarphase .title{
  display:flex;
  align-items:center;
  gap:8px;
}

.eventitem.songofday .songlink{
  display:block;
  margin-top:6px;
  color:var(--accent-yellow);
  text-decoration:none;
  font-size:13px;
  font-weight:600;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.eventitem.songofday .songlink:hover{
  text-decoration:underline;
}

.facts{
  display:flex;
  flex-direction:column;
  gap:6px;
}

.factrow{
  display:flex;
  justify-content:space-between;
  gap:10px;
  font-size:13px;
}

.factrow span:first-child{
  color:var(--muted);
}

/* Clocks */
.clocks{
  display:flex;
  flex-direction:column;
  gap:16px;
}

.clock-block{
  display:flex;
  flex-direction:column;
  gap:8px;
}

.tzlabel{
  font-size:12px;
  color:var(--muted);
}

.tzselect{
  height:34px;
  border:1px solid var(--line);
  border-radius:10px;
  padding:0 10px;
  font-family:var(--mono);
  background:rgba(255,255,255,0.10);
  color:var(--text);
}

.ampm{
  margin-top:6px;
  font-size:12px;
  color:var(--muted);
  text-align:right;
}

.clockface{
  width:100%;
  aspect-ratio:1 / 1;
  border:1px solid var(--line);
  border-radius:16px;
  background:rgba(255,255,255,0.08);
  display:flex;
  align-items:center;
  justify-content:center;
}

.superday-title{
  font-size:12px;
  color:var(--muted);
  text-transform:uppercase;
  letter-spacing:0.08em;
}

.superday-meta{
  font-size:13px;
  display:flex;
  flex-direction:column;
  gap:6px;
  margin-top:6px;
}

.superday-meta span{
  font-family:var(--mono);
}

/* Popover */
.popover{
  position:fixed;
  min-width:260px;
  max-width:340px;
  background:rgba(0,31,99,0.96);
  color:var(--text);
  border:1px solid var(--line);
  border-radius:14px;
  box-shadow:var(--shadow);
  padding:10px;
  z-index:50;
  backdrop-filter:blur(8px);
}

.popover .pop-title{
  font-weight:600;
  margin-bottom:6px;
}

.popover .pop-close{
  position:absolute;
  right:10px;
  top:8px;
  cursor:pointer;
  color:var(--muted);
  background:none;
  border:none;
}

.popover .pop-item{
  padding:8px 8px;
  border-radius:10px;
  border:1px solid var(--line);
  margin-top:8px;
  font-size:13px;
  background:rgba(255,255,255,0.08);
  color:var(--text);
}

/* Mobile bottom sheet */
.bottom-sheet{ display:none !important; }

/* AFdS page header */
.afds-header{
  position:sticky;
  top:0;
  z-index:120;

  display:grid;
  grid-template-columns:92px minmax(0, 1fr) 92px;
  align-items:center;
  gap:12px;

  min-height:var(--afds-header-h);
  padding:10px clamp(10px, 2vw, 20px);

  background:rgba(0,45,137,0.92);
  border-bottom:1px solid var(--line);
  box-shadow:0 6px 16px rgba(0,0,0,0.18);
  backdrop-filter:blur(8px);

  flex:0 0 auto;
}

.afds-header-side{
  display:flex;
  align-items:center;
}

.afds-header-left{
  justify-content:flex-start;
}

.afds-header-right{
  justify-content:flex-end;
}

.afds-title-wrap{
  min-width:0;
  text-align:center;
  padding:0 4px;
}

.afds-title{
  margin:0;
  font-size:clamp(1.15rem, 2.2vw, 1.9rem);
  line-height:1.15;
}

.afds-subtitle{
  margin-top:3px;
  font-size:12px;
  color:var(--muted);
  letter-spacing:0.08em;
  text-transform:uppercase;
  white-space:normal;
  overflow-wrap:anywhere;
}

.single-view-card{
  min-height:0;
  background:var(--panel);
  border:1px solid var(--line);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  backdrop-filter:blur(6px);
  padding:14px;
}

.single-view-card .panel-inner{
  padding:0;
  height:auto;
  overflow:visible;
}

.mobile-clocks-grid{
  display:grid;
  grid-template-columns:repeat(auto-fit, minmax(220px, 1fr));
  gap:14px;
}

.mobile-clock-card{
  border:1px solid var(--line);
  border-radius:14px;
  background:rgba(255,255,255,0.06);
  padding:12px;
}

.mobile-clock-label{
  font-size:12px;
  color:var(--muted);
  text-transform:uppercase;
  letter-spacing:0.08em;
  margin-bottom:4px;
}

.mobile-clock-zone{
  font-size:13px;
  color:var(--text);
  margin-bottom:8px;
  word-break:break-word;
}

.mobile-superday-meta{
  font-size:13px;
  display:flex;
  flex-direction:column;
  gap:6px;
  margin-top:8px;
}

.mobile-superday-meta span{
  font-family:var(--mono);
}

.afds-nav-btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-height:42px;
  padding:8px 14px;
  border-radius:10px;
  text-decoration:none;
  font-weight:600;
  white-space:nowrap;

  background:#7aa2ff;
  color:#0b1020;
  border:1px solid rgba(255,255,255,0.18);
  box-shadow:0 8px 18px rgba(0,0,0,0.28);
}

.afds-nav-btn:hover{
  filter:brightness(1.05);
}

.afds-nav-btn:focus-visible{
  outline:2px solid #fff;
  outline-offset:2px;
}

.afds-header-spacer{
  display:inline-block;
  min-width:92px;
  min-height:42px;
}

@media (max-width:700px){
  :root{
    --afds-header-h:60px;
  }

  .afds-header{
    grid-template-columns:76px minmax(0, 1fr) 76px;
    gap:10px;
    padding:8px 12px;
  }

  .afds-title{
    font-size:clamp(1rem, 4.2vw, 1.35rem);
  }

  .afds-subtitle{
    font-size:11px;
    line-height:1.2;
  }

  .afds-nav-btn{
    min-height:40px;
    padding:7px 12px;
    font-size:0.95rem;
  }

  .afds-header-spacer{
    min-width:76px;
    min-height:40px;
  }

  .mobile-clocks-grid{
    grid-template-columns:1fr;
  }
}

@media (max-width:1040px){
  body{
    overflow:auto;
  }

  .app{
    height:auto;
    min-height:100svh;
  }

  .panel.left,
  .panel.right{
    display:none;
  }

  .center{
    min-width:0;
  }

  .layout{
    padding:12px;
    min-height:auto;
  }

  .cal-header{
    padding:10px;
    gap:10px;
    flex-direction:column;
    align-items:stretch;
  }

  .nav{
    width:100%;
    flex-wrap:wrap;
    gap:8px;
  }

  .nav .btn{
    height:32px;
    padding:0 10px;
    font-size:0.95rem;
  }

  .nav .iconbtn{
    width:32px;
    height:32px;
    font-size:17px;
    line-height:30px;
  }

  .title{
    min-width:0;
    flex:1 1 100%;
    font-size:clamp(1.05rem, 4.4vw, 1.35rem);
  }

  .controls{
    width:100%;
    display:grid;
    grid-template-columns:minmax(110px, 130px) minmax(0, 1fr) auto;
    gap:10px 12px;
    align-items:end;
    justify-content:stretch;
  }

  .control-view{
    grid-column:1;
  }

  .control-displaytz{
    grid-column:2;
  }

  .control-mobile-gregorian{
    grid-column:3;
    display:flex;
  }

  .control-mobile-gregorian .toggle-inline{
    white-space:nowrap;
  }

  .control-desktop-only{
    display:none;
  }

  .control-view select,
  .control-displaytz select{
    width:100%;
    min-width:0;
  }

  .cal-surface{
    overflow:visible;
    min-height:auto;
    flex:none;
  }

  .dow,
  .week-dow{
    position:static;
  }

  .week-bars{
    position:static;
    top:auto;
  }

  .bottom-sheet{
    display:none !important;
  }
}

/* One-Off timed events */
.day-items{
  margin-top:8px;
  display:flex;
  flex-direction:column;
  gap:4px;
}

.day-item{
  font-size:11px;
  color:var(--text);
  opacity:0.9;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.day-item .t{
  font-family:var(--mono);
  color:var(--muted);
  margin-right:6px;
}

.oneoff-block{
  position:absolute;
  left:4px;
  right:4px;
  min-height:18px;
  border-radius:6px;
  padding:2px 4px;
  font-size:11px;
  font-weight:700;
  line-height:1.15;
  background:#7030A0;
  color:#f5ecff;
  border:1px solid rgba(255,255,255,0.22);
  overflow:hidden;
  white-space:nowrap;
  text-overflow:ellipsis;
  pointer-events:none;
}
