:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #f5f7f6;
  background: #0b0f0d;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at top left, #173522 0, #0b0f0d 34rem); }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.shell { width: min(1160px, calc(100% - 32px)); margin: 0 auto; padding: 44px 0 80px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(2rem, 5vw, 3.4rem); letter-spacing: -0.05em; }
h2 { margin-bottom: 10px; font-size: 1.35rem; letter-spacing: -0.02em; }
p { line-height: 1.6; color: #b4bdb8; }
.eyebrow { margin-bottom: 8px; color: #58dd88; text-transform: uppercase; font-size: .72rem; letter-spacing: .17em; font-weight: 800; }
.muted { color: #89938e; }
.hidden { display: none !important; }

.card { border: 1px solid #25312b; background: rgba(17, 23, 20, .88); border-radius: 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, .22); }
.hero { padding: clamp(28px, 6vw, 64px); display: flex; justify-content: space-between; align-items: end; gap: 30px; }
.hero h2 { max-width: 720px; font-size: clamp(2rem, 5vw, 4rem); line-height: 1; letter-spacing: -.055em; }
.hero p { max-width: 650px; }

.button { border: 1px solid #34423b; background: #18201c; color: #fff; border-radius: 12px; padding: 11px 16px; cursor: pointer; text-decoration: none; font-weight: 750; transition: transform .15s ease, border-color .15s ease, background .15s ease; }
.button:hover { transform: translateY(-1px); border-color: #52655b; }
.button.primary { background: #1ed760; color: #07110a; border-color: #1ed760; }
.button.subtle { background: transparent; color: #b4bdb8; }
.button.wide { width: 100%; margin-top: 20px; }

.profile-pill { display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 8px; border: 1px solid #28342e; border-radius: 999px; background: #111713; }
.profile-pill img { width: 34px; height: 34px; object-fit: cover; border-radius: 50%; }
.profile-pill .avatar { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: #27352d; }
.profile-actions { display: flex; gap: 8px; margin-left: 6px; }
.icon-button { border: 0; background: transparent; color: #89938e; cursor: pointer; padding: 7px; }

.status { min-height: 130px; padding: 24px; margin-bottom: 18px; display: flex; justify-content: space-between; align-items: center; }
.status h2 { font-size: 1.6rem; }
.cover { width: 84px; height: 84px; border-radius: 14px; object-fit: cover; }
.device-capability { margin-top: 12px; max-width: 760px; padding: 10px 12px; border: 1px solid #314139; border-radius: 12px; font-size: .82rem; line-height: 1.45; }
.device-capability.available { border-color: #1f6537; color: #70e799; background: #112b1a; }
.device-capability.blocked { border-color: #7a5425; color: #ffd29a; background: #2a1c0d; }

.grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(250px, .8fr); gap: 18px; }
.search-card, .explainer, .rules-card { padding: 24px; }
.rules-card { margin-top: 18px; }
.section-heading { display: flex; justify-content: space-between; gap: 20px; align-items: center; }
.segmented { padding: 4px; border: 1px solid #29362f; border-radius: 12px; display: flex; background: #0c110e; }
.segment { border: 0; background: transparent; color: #8f9b95; border-radius: 8px; padding: 8px 12px; cursor: pointer; }
.segment.active { background: #26342c; color: #fff; }
.search-row { display: flex; gap: 10px; margin: 18px 0; }
.search-row input { min-width: 0; flex: 1; border: 1px solid #2e3b35; border-radius: 12px; background: #0d120f; color: #fff; padding: 12px 14px; outline: none; }
.search-row input:focus { border-color: #58dd88; box-shadow: 0 0 0 3px rgba(88, 221, 136, .1); }

.results, .rules { display: grid; gap: 9px; }
.result, .rule { display: flex; align-items: center; gap: 12px; padding: 11px; border: 1px solid #26322c; border-radius: 14px; background: #0e1411; }
.item-image, .item-fallback { width: 48px; height: 48px; flex: 0 0 48px; border-radius: 9px; object-fit: cover; background: #26322c; }
.item-fallback { display: grid; place-items: center; color: #58dd88; font-weight: 900; }
.item-copy { min-width: 0; flex: 1; }
.item-copy strong, .item-copy small { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.item-copy small { margin-top: 4px; color: #89938e; }
.rule-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 7px; }
.badge { padding: 4px 7px; border: 1px solid #314139; border-radius: 999px; color: #aeb9b3; font-size: .72rem; }
.badge.green { border-color: #1f6537; color: #70e799; background: #112b1a; }
.empty { padding: 26px 8px; text-align: center; color: #76827c; }
.error { color: #ff9d9d; }

.explainer { align-self: start; }

#ruleDialog { width: min(520px, calc(100% - 28px)); border: 1px solid #334139; border-radius: 20px; background: #111713; color: #fff; padding: 0; }
#ruleDialog::backdrop { background: rgba(0, 0, 0, .72); backdrop-filter: blur(5px); }
#ruleForm { padding: 28px; position: relative; }
.dialog-close { position: absolute; right: 18px; top: 14px; border: 0; background: transparent; color: #849089; font-size: 1.8rem; cursor: pointer; }
.choice { display: flex; gap: 10px; align-items: flex-start; border: 1px solid #29362f; border-radius: 14px; padding: 14px; margin-top: 10px; cursor: pointer; }
.choice strong, .choice small { display: block; }
.choice small { color: #89938e; margin-top: 4px; }
.choice input { margin-top: 4px; accent-color: #1ed760; }
.window-choices { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.window-choices label { border: 1px solid #29362f; border-radius: 10px; padding: 10px; text-align: center; cursor: pointer; }
.window-choices input { accent-color: #1ed760; }
.window-choices.disabled { opacity: .42; pointer-events: none; }

@media (max-width: 760px) {
  .shell { width: min(100% - 20px, 1160px); padding-top: 24px; }
  .topbar, .hero, .section-heading { align-items: flex-start; }
  .topbar, .hero { flex-direction: column; }
  .grid { grid-template-columns: 1fr; }
  .section-heading { gap: 10px; }
  .profile-pill { max-width: 100%; }
  .profile-name { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

.global-rule-callouts { display: grid; gap: 10px; margin: 2px 0 18px; }
.global-rule-callout { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 0; padding: 13px 14px; border: 1px solid #2a3931; border-radius: 14px; background: #111a15; }
.global-rule-callout strong, .global-rule-callout small { display: block; }
.global-rule-callout small { margin-top: 4px; color: #89938e; }
.all-fallback { font-size: .62rem; letter-spacing: .06em; }
.threshold-options { margin-top: 12px; }
.threshold-options.disabled { opacity: .42; pointer-events: none; }
.limit-field { display: grid; gap: 7px; margin-bottom: 12px; color: #b4bdb8; font-size: .84rem; font-weight: 700; }
.limit-field input { width: 100%; border: 1px solid #2e3b35; border-radius: 11px; background: #0d120f; color: #fff; padding: 11px 12px; outline: none; }
.limit-field input:focus { border-color: #58dd88; box-shadow: 0 0 0 3px rgba(88, 221, 136, .1); }

@media (max-width: 560px) {
  .window-choices { grid-template-columns: repeat(2, 1fr); }
  .global-rule-callout { align-items: flex-start; flex-direction: column; }
}

.history-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr); gap: 18px; margin-top: 18px; }
.history-card { padding: 24px; min-width: 0; }
.section-meta { margin: 3px 0 0; color: #76827c; font-size: .82rem; line-height: 1.4; }
.listen-feed, .listen-summary { display: grid; gap: 9px; margin-top: 18px; }
.listen-event { display: flex; align-items: center; gap: 12px; padding: 11px; border: 1px solid #26322c; border-radius: 14px; background: #0e1411; }
.listen-event time { flex: 0 0 auto; color: #7f8b85; font-size: .76rem; text-align: right; }
.listen-image { width: 46px; height: 46px; flex: 0 0 46px; border-radius: 9px; object-fit: cover; background: #26322c; }
div.listen-image { display: grid; place-items: center; color: #58dd88; font-weight: 900; }
.listen-track { border: 1px solid #26322c; border-radius: 14px; background: #0e1411; overflow: hidden; }
.listen-track summary { display: flex; align-items: center; gap: 12px; padding: 11px; cursor: pointer; list-style: none; }
.listen-track summary::-webkit-details-marker { display: none; }
.listen-track summary::after { content: "›"; color: #718078; font-size: 1.25rem; transition: transform .15s ease; }
.listen-track[open] summary::after { transform: rotate(90deg); }
.listen-count { flex: 0 0 auto; min-width: 54px; text-align: right; color: #70e799; font-weight: 850; }
.listen-track-history { border-top: 1px solid #26322c; padding: 10px 14px 14px 72px; }
.listen-times-list { display: grid; gap: 6px; }
.listen-time { color: #aeb9b3; font-size: .82rem; padding: 5px 0; border-bottom: 1px solid rgba(49, 65, 57, .45); }
.listen-time:last-child { border-bottom: 0; }
.listen-times-status { font-size: .82rem; padding: 5px 0; }
.track-history-more { margin-top: 9px; }

@media (max-width: 900px) {
  .history-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .listen-event { align-items: flex-start; flex-wrap: wrap; }
  .listen-event time { width: 100%; padding-left: 58px; text-align: left; }
  .listen-track-history { padding-left: 14px; }
}

.profile-controls { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(260px, .65fr); gap: 1px; margin-bottom: 18px; overflow: hidden; background: #25312b; }
.profile-config, .service-control { padding: 22px 24px; background: #111713; }
.profile-config { display: flex; align-items: center; justify-content: space-between; gap: 22px; }
.service-control { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.profile-control-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.profile-control-row select { min-width: 180px; max-width: 280px; border: 1px solid #2e3b35; border-radius: 12px; background: #0d120f; color: #fff; padding: 10px 36px 10px 12px; outline: none; }
.profile-control-row select:focus { border-color: #58dd88; box-shadow: 0 0 0 3px rgba(88, 221, 136, .1); }
.heading-profile { color: #70e799; font-size: .82rem; font-weight: 750; letter-spacing: 0; white-space: nowrap; }
button:disabled, select:disabled { cursor: not-allowed; opacity: .48; transform: none !important; }

@media (max-width: 900px) {
  .profile-controls { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  .profile-config, .service-control { align-items: flex-start; flex-direction: column; }
  .profile-control-row { width: 100%; justify-content: flex-start; }
  .profile-control-row select { width: 100%; max-width: none; }
}

.rule-copy { min-width: 0; }
.rule-actions { display: flex; gap: 7px; flex: 0 0 auto; }
.rule-progress { margin-top: 10px; max-width: 620px; }
.rule-progress-head, .rule-progress-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: .76rem; }
.rule-progress-head strong { color: #dbe2de; font-size: .78rem; }
.rule-progress-head span, .rule-progress-foot { color: #89938e; }
.rule-progress-track { display: block; width: 100%; height: 7px; margin: 6px 0; overflow: hidden; border: 0; border-radius: 999px; background: #26322c; appearance: none; }
.rule-progress-track::-webkit-progress-bar { background: #26322c; border-radius: 999px; }
.rule-progress-track::-webkit-progress-value { background: #1ed760; border-radius: 999px; }
.rule-progress-track::-moz-progress-bar { background: #1ed760; border-radius: 999px; }
.rule-progress-copy { margin-top: 9px; display: flex; gap: 8px; flex-wrap: wrap; align-items: baseline; font-size: .76rem; }
.rule-progress-copy strong { color: #70e799; }
.rule-progress-copy span { color: #89938e; }
.rule-countdown { white-space: nowrap; }

@media (max-width: 680px) {
  .rule { align-items: flex-start; flex-wrap: wrap; }
  .rule-copy { flex-basis: calc(100% - 60px); }
  .rule-actions { width: 100%; padding-left: 60px; }
  .rule-progress-head, .rule-progress-foot { align-items: flex-start; flex-direction: column; gap: 3px; }
}

.exception-section { margin-top: 18px; padding-top: 18px; border-top: 1px solid #29362f; }
.exception-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.exception-heading strong, .exception-heading small { display: block; }
.exception-heading small { margin-top: 4px; color: #89938e; }
.exception-list, .exception-results { display: grid; gap: 7px; margin-top: 10px; }
.exception-search-row { display: flex; gap: 8px; margin-top: 12px; }
.exception-search-row input { min-width: 0; flex: 1; border: 1px solid #2e3b35; border-radius: 11px; background: #0d120f; color: #fff; padding: 10px 12px; outline: none; }
.exception-search-row input:focus { border-color: #58dd88; box-shadow: 0 0 0 3px rgba(88, 221, 136, .1); }
.exception-item, .exception-result { display: flex; align-items: center; gap: 9px; padding: 8px; border: 1px solid #29362f; border-radius: 11px; background: #0d120f; }
.exception-item .item-image, .exception-item .item-fallback, .exception-result .item-image, .exception-result .item-fallback { width: 38px; height: 38px; flex-basis: 38px; }
.exception-item .button, .exception-result .button { padding: 7px 10px; }

.rule-subjects { margin-top: 10px; max-width: 680px; border: 1px solid #29362f; border-radius: 12px; background: #0c120f; overflow: hidden; }
.rule-subjects > summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; cursor: pointer; color: #b9c3be; font-size: .78rem; list-style: none; }
.rule-subjects > summary::-webkit-details-marker { display: none; }
.rule-subjects > summary::after { content: "▾"; color: #70e799; transition: transform .15s ease; }
.rule-subjects[open] > summary::after { transform: rotate(180deg); }
.rule-subject-list { display: grid; border-top: 1px solid #29362f; }
.rule-subject-row { display: grid; grid-template-columns: 38px minmax(0, 1fr); gap: 10px; padding: 10px 12px; border-bottom: 1px solid #202b25; }
.rule-subject-row:last-child { border-bottom: 0; }
.rule-subject-row .item-image, .rule-subject-row .item-fallback { width: 38px; height: 38px; flex-basis: 38px; }
.rule-subject-main { min-width: 0; }
.rule-subject-title { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.rule-subject-title strong, .rule-subject-title span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.rule-subject-title strong { color: #dbe2de; font-size: .8rem; }
.rule-subject-title span { color: #a9b3ae; font-size: .75rem; flex: 0 0 auto; }
.rule-subject-subtitle { margin-top: 2px; color: #7f8b85; font-size: .72rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.rule-subject-foot { display: flex; justify-content: space-between; gap: 10px; margin-top: 5px; color: #89938e; font-size: .71rem; }
.rule-subject-status { padding: 12px; color: #89938e; font-size: .76rem; }
.rule-subject-more { margin: 0 12px 12px; width: calc(100% - 24px); }

@media (max-width: 560px) {
  .exception-search-row { flex-direction: column; }
  .rule-subject-title, .rule-subject-foot { align-items: flex-start; flex-direction: column; gap: 3px; }
}

/* History-backed counter controls */
.counter-reset { border: 0; padding: 0; background: transparent; color: #70e799; font: inherit; font-size: .72rem; font-weight: 750; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.counter-reset:hover { color: #a0f1bb; }
.listen-badges { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 5px; }
.listen-badges .badge { font-size: .62rem; padding: 3px 6px; }
.forgiven-badge { color: #b7c1bc !important; border-color: #425048 !important; background: #151d19 !important; }
.listen-event.forgiven, .listen-time.forgiven { opacity: .62; }
.listen-event.forgiven strong { text-decoration: line-through; text-decoration-thickness: 1px; }
.listen-event-side { margin-left: auto; display: grid; justify-items: end; gap: 6px; flex: 0 0 auto; }
.listen-time { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.listen-time .listen-badges { display: inline-flex; margin: 0 0 0 7px; vertical-align: middle; }

@media (max-width: 560px) {
  .listen-event-side { width: 100%; margin-left: 58px; justify-items: start; }
  .listen-event-side time { width: auto; padding-left: 0; }
  .listen-time { align-items: flex-start; flex-direction: column; gap: 5px; }
}
