:root {
  color-scheme: light dark;
  --bg: var(--tg-theme-bg-color, #f1f3ec);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --surface-strong: #121713;
  --text: var(--tg-theme-text-color, #161b17);
  --muted: var(--tg-theme-hint-color, #68716a);
  --line: color-mix(in srgb, var(--text) 14%, transparent);
  --accent: var(--tg-theme-button-color, #19c37d);
  --accent-text: var(--tg-theme-button-text-color, #08140d);
  --lime: #a8f06a;
  --danger: #e45454;
  --warning: #f3c969;
  --radius: 18px;
  --shadow: 0 12px 40px rgba(23, 31, 25, .10);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--bg); }
body { margin: 0; min-width: 320px; min-height: 100vh; min-height: var(--tg-viewport-stable-height, 100vh); background: var(--bg); color: var(--text); }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }

.app-shell { width: min(100%, 1120px); margin: 0 auto; padding-top: max(env(safe-area-inset-top), var(--tg-safe-area-inset-top, 0px), var(--tg-content-safe-area-inset-top, 0px)); padding-right: max(14px, env(safe-area-inset-right), var(--tg-safe-area-inset-right, 0px)); padding-bottom: max(calc(20px + env(safe-area-inset-bottom)), calc(20px + var(--tg-safe-area-inset-bottom, 0px))); padding-left: max(14px, env(safe-area-inset-left), var(--tg-safe-area-inset-left, 0px)); }
main { padding-top: 6px; }
.home-layout { display: grid; gap: 10px; }
.intro { padding: 10px 2px 0; }
.eyebrow { display: block; margin-bottom: 10px; color: var(--muted); font-size: .76rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { max-width: 760px; margin-bottom: 10px; font-family: Georgia, "Times New Roman", serif; font-size: clamp(2.45rem, 11vw, 5.8rem); line-height: .91; letter-spacing: -.055em; font-weight: 500; }
.intro p { max-width: 560px; margin-bottom: 0; color: var(--muted); font-size: 1.02rem; line-height: 1.4; }
.accent-word { color: #0f9d65; font-style: italic; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.create-card { padding: 16px; }
.create-card h2 { margin-bottom: 4px; font: 600 1.55rem/1.15 Georgia, serif; }
.form-note { margin-bottom: 14px; color: var(--muted); font-size: .9rem; line-height: 1.35; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: grid; gap: 5px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field span { font-size: .82rem; font-weight: 750; }
.field input, .field select { width: 100%; min-height: 48px; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: color-mix(in srgb, var(--surface) 92%, var(--text) 8%); color: var(--text); outline: none; }
.field input:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }

.button { min-height: 46px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; border-radius: 13px; padding: 10px 16px; background: var(--surface-strong); color: #fff; font-weight: 800; text-decoration: none; cursor: pointer; transition: transform .15s ease, opacity .15s ease, background .15s ease; }
.button:hover { transform: translateY(-1px); }
.button:active { transform: translateY(0); }
.button:disabled { cursor: not-allowed; opacity: .5; transform: none; }
.button.primary { background: var(--accent); color: var(--accent-text); }
.button.secondary { border-color: var(--line); background: var(--surface); color: var(--text); }
.button.danger-soft { background: color-mix(in srgb, var(--danger) 13%, var(--surface)); color: var(--danger); }
.create-submit { width: 100%; margin-top: 14px; }

.loader-card { min-height: 60vh; display: grid; place-items: center; align-content: center; gap: 14px; color: var(--muted); }
.loader { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.error-card, .join-card { padding: 26px; max-width: 560px; margin: 10vh auto 0; text-align: center; }
.error-card h2, .join-card h2 { font: 600 1.8rem/1.1 Georgia, serif; }
.error-card p, .join-card p { color: var(--muted); line-height: 1.5; }
.created-share { display: grid; gap: 16px; margin: 22px 0 0; }
.join-card .created-share .share-hint { margin: 0; }
.created-share .button { width: 100%; }
.event-page { display: grid; gap: 14px; }
.notice { padding: 12px 14px; border: 1px solid color-mix(in srgb, var(--warning) 45%, var(--line)); border-radius: 13px; background: color-mix(in srgb, var(--warning) 12%, var(--surface)); font-size: .9rem; line-height: 1.45; }

.vote-card { overflow: hidden; }
.vote-head { display: grid; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.vote-head-readonly p { margin: 0; color: var(--muted); font-size: .82rem; line-height: 1.4; }
.mode-copy { display: grid; gap: 2px; }
.mode-title { min-width: 0; font-size: .88rem; font-weight: 780; line-height: 1.3; }
.mode-copy #instruction { color: var(--muted); font-size: .72rem; line-height: 1.3; }
.mode-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; padding: 3px; border-radius: 11px; background: color-mix(in srgb, var(--surface) 84%, var(--text) 16%); }
.mode-option { min-height: 38px; border: 0; border-radius: 8px; padding: 7px 12px; background: transparent; color: var(--muted); font-size: .8rem; font-weight: 780; cursor: pointer; transition: background .15s ease, color .15s ease, box-shadow .15s ease; }
.mode-option[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, .14); }
.mode-option:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.calendar-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 13px 18px; }
.calendar-nav button { min-height: 44px; border: 1px solid var(--line); border-radius: 11px; padding: 8px 12px; background: var(--surface); color: var(--text); font-weight: 750; cursor: pointer; }
.calendar-nav button:disabled { opacity: .35; }
.calendar-nav strong { text-align: center; font-size: .85rem; }

.calendar-wrap { overflow: hidden; border-top: 1px solid var(--line); }
.calendar-grid { display: grid; width: 100%; user-select: none; -webkit-user-select: none; touch-action: none; }
.calendar-corner, .day-head, .time-head, .slot { min-width: 0; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.calendar-corner, .time-head { position: sticky; left: 0; z-index: 5; background: var(--surface); }
.calendar-corner { z-index: 8; }
.day-head { min-height: 54px; display: grid; place-items: center; align-content: center; gap: 2px; padding: 6px 2px; background: color-mix(in srgb, var(--surface) 92%, var(--accent) 8%); text-align: center; cursor: grab; }
.day-head b { font-size: .74rem; text-transform: uppercase; }
.day-head span { color: var(--muted); font-size: .69rem; }
.day-head.today { background: var(--surface-strong); color: white; }
.day-head.today span { color: var(--lime); }
.time-head { min-height: 48px; display: grid; place-items: center; padding: 4px; color: var(--muted); font-size: .7rem; font-weight: 750; cursor: grab; }
.time-head.is-panning, .day-head.is-panning, .calendar-corner.is-panning { cursor: grabbing; background: color-mix(in srgb, var(--surface) 82%, var(--accent) 18%); }
.slot { min-height: 48px; position: relative; display: grid; place-items: center; border-top: 0; border-left: 0; border-radius: 0; padding: 0; background: var(--slot-bg, color-mix(in srgb, var(--surface) 95%, var(--text) 5%)); color: var(--text); cursor: pointer; }
.slot::before { content: attr(data-count); position: relative; z-index: 2; font-size: .66rem; font-weight: 800; }
.slot.own-available::after, .slot.own-busy::after { content: ""; position: absolute; inset: 3px; border-radius: 7px; pointer-events: none; }
.slot.own-available::after { border: 2px solid #087c50; }
.slot.own-busy::after { border: 2px dashed var(--danger); background-image: repeating-linear-gradient(135deg, transparent 0 5px, rgba(212, 69, 69, .20) 5px 8px); }
.calendar-grid.mode-mark-free .slot.own-busy::after { border-color: color-mix(in srgb, var(--danger) 78%, var(--text)); background: color-mix(in srgb, var(--danger) 22%, transparent); }
.calendar-grid.mode-mark-free .slot.own-available::after { border-color: #087c50; background: color-mix(in srgb, #42dc72 42%, transparent); }
.slot.is-painting { outline: 3px solid var(--text); outline-offset: -3px; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; padding: 13px 18px; color: var(--muted); font-size: .75rem; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 14px; border-radius: 4px; }
.legend .mine-busy i { border: 2px dashed var(--danger); background: transparent; }
.legend .mine-free i { border: 2px solid #087c50; background: color-mix(in srgb, #42dc72 42%, transparent); }
.legend .group i { background: #42dc72; }
.ready-wrap { padding: 4px 18px 18px; }
.ready-wrap .button { width: 100%; }

.best-card { padding: 18px; }
.best-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.best-card h2 { margin: 0; font: 600 1.5rem/1.1 Georgia, serif; }
.response-count { flex: none; color: var(--muted); font-size: .78rem; }
.response-count strong { color: var(--text); font-size: .9rem; }
.best-card > p { color: var(--muted); font-size: .86rem; }
.best-list { display: grid; gap: 9px; margin: 0; padding: 0; list-style: none; counter-reset: best; }
.best-item { counter-increment: best; display: grid; grid-template-columns: 35px 1fr; gap: 10px; padding: 13px; border: 1px solid var(--line); border-radius: 14px; }
.best-item::before { content: counter(best); width: 32px; height: 32px; display: grid; place-items: center; border-radius: 10px; background: var(--surface-strong); color: var(--lime); font-weight: 900; }
.best-item b { display: block; margin-bottom: 4px; font-size: .9rem; }
.best-item span { color: var(--muted); font-size: .8rem; line-height: 1.4; }
.empty { color: var(--muted); padding: 16px 0; }

.participant-status-card { padding: 18px; }
.participant-status-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.participant-status-head h2 { margin: 0; font: 600 1.5rem/1.1 Georgia, serif; }
.participant-status-head > span { color: var(--muted); font-size: .78rem; }
.participant-status-list { margin: 0; padding: 0; list-style: none; }
.participant-status-item { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 14px; border-top: 1px solid var(--line); padding: 10px 0; }
.participant-status-item:first-child { border-top: 0; }
.participant-identity { min-width: 0; display: grid; gap: 2px; }
.participant-identity b { overflow-wrap: anywhere; font-size: .9rem; }
.participant-identity > span { color: var(--muted); font-size: .78rem; }
.participant-vote-status { flex: none; display: inline-flex; align-items: center; gap: 6px; font-size: .76rem; font-weight: 750; }
.participant-vote-status i { width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.participant-vote-status.not-responded { color: var(--danger); }
.participant-vote-status.has-responded { color: #087c50; }

.toast { position: fixed; z-index: 100; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(calc(100% - 28px), 520px); border-radius: 13px; padding: 13px 16px; background: #121713; color: white; box-shadow: 0 16px 50px #0004; text-align: center; font-size: .88rem; }
.slot-dialog { width: min(calc(100% - 28px), 430px); border: 1px solid var(--line); border-radius: 18px; padding: 22px; background: var(--surface); color: var(--text); box-shadow: 0 25px 80px #0006; }
.slot-dialog::backdrop { background: rgba(0, 0, 0, .45); backdrop-filter: blur(3px); }
.dialog-close { position: absolute; right: 10px; top: 8px; width: 44px; height: 44px; border: 0; background: none; font-size: 1.7rem; cursor: pointer; }
.slot-dialog h3 { padding-right: 35px; font: 600 1.25rem/1.25 Georgia, serif; }
.slot-dialog p { margin-bottom: 7px; color: var(--muted); line-height: 1.45; }

.admin-body { padding: 0 14px 40px; }
.admin-wrap { width: min(100%, 1000px); margin: 0 auto; }
.admin-head { min-height: 110px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.admin-head h1 { margin: 0; font-size: clamp(2rem, 6vw, 3.5rem); }
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat-grid article { display: grid; gap: 4px; padding: 18px; border-radius: 16px; background: var(--surface-strong); color: white; }
.stat-grid strong { color: var(--lime); font: 500 2.2rem/1 Georgia, serif; }
.stat-grid span { color: #b9c1ba; font-size: .8rem; }
.admin-list { margin-top: 28px; }
.admin-event { border-top: 1px solid var(--line); }
.admin-event summary { min-height: 66px; display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; }
.admin-event summary span:first-child { display: grid; gap: 4px; }
.admin-event small { color: var(--muted); }
.admin-numbers { font-size: .82rem; text-align: right; }
.admin-event-body { padding: 0 14px 18px; color: var(--muted); font-size: .88rem; }
.admin-event-body li { margin-bottom: 7px; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 16px; padding-top: 24px; }

@media (min-width: 700px) {
  .app-shell { padding-left: 24px; padding-right: 24px; }
  .home-layout { grid-template-columns: minmax(0, 1.15fr) minmax(360px, .85fr); align-items: center; min-height: calc(100vh - 120px); }
  .create-card { padding: 28px; }
  .vote-head { grid-template-columns: minmax(240px, 1fr) 300px; align-items: center; padding: 14px 22px; }
  .vote-head-readonly { grid-template-columns: 1fr; }
  .calendar-nav { padding: 14px 22px; }
  .calendar-wrap { overflow-x: auto; }
  .calendar-grid { min-width: 650px; }
  .legend { padding: 14px 22px; }
  .ready-wrap { padding: 4px 22px 22px; }
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 699px) and (max-height: 700px) {
  main { padding-top: 4px; }
  .home-layout { gap: 8px; }
  .intro { padding-top: 6px; }
  h1 { margin-bottom: 8px; font-size: clamp(2.15rem, 10vw, 4.8rem); }
  .intro p { font-size: .96rem; line-height: 1.35; }
  .create-card { padding: 14px; }
  .create-card h2 { font-size: 1.45rem; }
  .form-note { margin-bottom: 10px; font-size: .85rem; }
  .form-grid { row-gap: 8px; }
  .field { gap: 4px; }
  .field input, .field select { min-height: 44px; padding: 8px 10px; }
  .button { min-height: 44px; }
  .create-submit { margin-top: 12px; }
}

@media (prefers-color-scheme: dark) {
  :root { --bg: var(--tg-theme-bg-color, #101411); --surface: var(--tg-theme-secondary-bg-color, #1a201b); --surface-strong: #070a08; --text: var(--tg-theme-text-color, #f0f5f0); --muted: var(--tg-theme-hint-color, #9ba69d); --line: rgba(255,255,255,.12); --shadow: 0 16px 50px rgba(0,0,0,.24); }
  .accent-word { color: var(--lime); }
}

@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .001ms !important; transition-duration: .001ms !important; } }
