:root {
  --bg: var(--tg-theme-bg-color, #f4f4f5);
  --card: var(--tg-theme-section-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1c1c1e);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --btn: var(--tg-theme-button-color, #007aff);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #e53935);
  --line: var(--tg-theme-section-separator-color, rgba(0, 0, 0, 0.14));
  --field: var(--tg-theme-secondary-bg-color, #ffffff);
  color-scheme: light;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --line: var(--tg-theme-section-separator-color, rgba(255, 255, 255, 0.18));
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
  padding: 20px 16px calc(32px + env(safe-area-inset-bottom));
}

main {
  width: min(100%, 460px);
  margin: 0 auto;
}

h1, h2, p { margin: 0; }

.eyebrow {
  margin-bottom: 6px;
  color: var(--btn);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

header h1, #gate h1 {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.2;
}

header { margin-bottom: 18px; }

h2 {
  margin: 0 0 10px 2px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--hint);
}

.card, .item, .empty {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 20px;
}

.card { padding: 14px; }

.switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  background: transparent;
}

.switch button, .days button, .ghost, .primary {
  font: inherit;
  cursor: pointer;
}

.switch button {
  height: 42px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--hint);
  font-weight: 600;
}

.switch button.on {
  background: var(--btn);
  color: var(--btn-text);
}

.hint {
  margin: 14px 2px 0;
  color: var(--hint);
  font-size: 14px;
  line-height: 1.4;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

.field > span {
  font-size: 13px;
  font-weight: 600;
  color: var(--hint);
}

textarea, .picker-field {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: var(--field);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  padding: 14px 14px;
}

.picker-field {
  display: flex;
  align-items: center;
  min-height: 52px;
  text-align: left;
  appearance: none;
}

textarea {
  resize: none;
  min-height: 84px;
  line-height: 1.4;
}

textarea::placeholder { color: var(--hint); }

textarea:focus, .picker-field:focus {
  outline: none;
  border-color: var(--btn);
}

.days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.days button {
  aspect-ratio: 1;
  min-width: 0;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: var(--field);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  padding: 0;
}

.days button.on {
  background: var(--btn);
  border-color: var(--btn);
  color: var(--btn-text);
}

.error {
  margin: 12px 2px 0;
  color: var(--danger);
  font-size: 14px;
}

.primary, .quiet {
  width: 100%;
  height: 48px;
  min-width: 0;
  margin-top: 16px;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 700;
}

.primary {
  border: 0;
  background: var(--btn);
  color: var(--btn-text);
}

.quiet {
  border: 1.5px solid var(--line);
  background: transparent;
  color: var(--text);
}

.primary:disabled { opacity: 0.5; }

.list-wrap { margin-top: 22px; }

.item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  margin-bottom: 8px;
}

.item div {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  flex: 1;
}

.item strong {
  font-size: 16px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.item span, .empty, #gate p {
  color: var(--hint);
  font-size: 14px;
  line-height: 1.4;
}

.ghost {
  flex: none;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: transparent;
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 10px;
}

.empty {
  padding: 22px 16px;
  text-align: center;
  border-style: dashed;
}

#gate { padding-top: 18vh; }

#gate p { margin-top: 8px; }

#sheet {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, 0.5);
}

#sheet[hidden] { display: none; }

.sheet-card {
  width: min(100%, 420px);
  max-height: min(82vh, 620px);
  overflow: auto;
  padding: 16px;
  border: 1.5px solid var(--line);
  border-radius: 22px;
  background: var(--card);
}

.sheet-title {
  margin-bottom: 12px;
  font-size: 18px;
  font-weight: 700;
}

.sheet-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
}

.sheet-actions .primary,
.sheet-actions .quiet {
  margin-top: 14px;
}

.wheels {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.colon {
  font-size: 28px;
  font-weight: 700;
}

.wheel {
  height: 188px;
  overflow-y: auto;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  background: var(--field);
}

.wheel button {
  display: block;
  width: 100%;
  height: 44px;
  border: 0;
  background: transparent;
  color: var(--hint);
  font: inherit;
  font-size: 20px;
  font-weight: 600;
}

.wheel button.on {
  background: var(--btn);
  color: var(--btn-text);
}

.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.cal-nav strong {
  min-width: 0;
  font-size: 16px;
  text-align: center;
}

.cal-nav button, .cal-grid button {
  border: 1.5px solid var(--line);
  background: var(--field);
  color: var(--text);
  font: inherit;
}

.cal-nav button {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 12px;
  font-size: 20px;
}

.cal-head, .cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

.cal-head span {
  color: var(--hint);
  font-size: 11px;
  font-weight: 600;
  text-align: center;
}

.cal-grid { margin-top: 6px; }

.cal-grid button {
  aspect-ratio: 1;
  min-width: 0;
  border-radius: 12px;
  padding: 0;
  font-size: 14px;
  font-weight: 600;
}

.cal-grid button.on {
  border-color: var(--btn);
  background: var(--btn);
  color: var(--btn-text);
}

.cal-grid button:disabled {
  opacity: 0.3;
}
