:root {
  color-scheme: light;
  --paper: #f4f1e8;
  --surface: #fffdf7;
  --surface-strong: #ebe6d8;
  --ink: #18302b;
  --muted: #62706b;
  --line: #d8d2c3;
  --green: #145c4e;
  --green-deep: #0d443a;
  --green-soft: #dcebe5;
  --gold: #c28a2c;
  --danger: #a13b32;
  --shadow: 0 24px 60px rgba(38, 45, 40, 0.12);
  --radius: 18px;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--paper);
}

body {
  min-height: 100%;
  margin: 0;
  background:
    radial-gradient(circle at 8% 4%, rgba(194, 138, 44, 0.15), transparent 26rem),
    radial-gradient(circle at 96% 18%, rgba(20, 92, 78, 0.12), transparent 30rem),
    var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button,
a,
input {
  touch-action: manipulation;
}

button {
  border: 0;
  cursor: pointer;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 4px solid rgba(194, 138, 44, 0.35);
  outline-offset: 3px;
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  min-height: 68px;
  padding: max(12px, env(safe-area-inset-top)) max(22px, env(safe-area-inset-right)) 12px max(22px, env(safe-area-inset-left));
  border-bottom: 1px solid rgba(216, 210, 195, 0.78);
  background: rgba(244, 241, 232, 0.88);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.back-link {
  flex: 0 1 auto;
  min-width: 0;
  color: var(--green-deep);
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 9px;
}

.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 253, 247, 0.92);
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.sync-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 4px rgba(194, 138, 44, 0.13);
}

.sync-pill.synced .sync-dot {
  background: #27836f;
  box-shadow: 0 0 0 4px rgba(39, 131, 111, 0.13);
}

.sync-pill.offline .sync-dot {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(161, 59, 50, 0.12);
}

.language-button {
  min-height: 42px;
  padding: 8px 13px;
  border: 1px solid var(--green);
  border-radius: 999px;
  background: var(--green);
  color: white;
  font-size: 0.86rem;
  font-weight: 850;
}

.page-shell {
  width: min(1100px, calc(100% - 36px));
  margin: 0 auto;
  padding: clamp(24px, 5vw, 62px) 0 max(42px, env(safe-area-inset-bottom));
}

.hero {
  display: grid;
  gap: 24px;
}

.hero-copy {
  max-width: 760px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--green);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.18em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  font-size: clamp(2.4rem, 8vw, 5rem);
  line-height: 0.98;
  letter-spacing: -0.045em;
}

.hero-copy > p:last-child {
  margin-bottom: 0;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.18rem);
  line-height: 1.75;
}

.rights-banner {
  grid-column: 1 / -1;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--green);
  border-radius: 14px;
  background: rgba(255, 253, 247, 0.92);
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.65;
}

.rights-banner p {
  margin: 0;
}

.rights-banner p + p {
  margin-top: 3px;
}

.rights-banner strong,
.rights-banner a {
  color: var(--green-deep);
  font-weight: 850;
}

.rights-banner a {
  text-underline-offset: 3px;
}

html[lang="ja"] .rights-en,
html[lang="en"] .rights-ja {
  display: none;
}

.clock-card {
  position: relative;
  overflow: hidden;
  padding: clamp(28px, 6vw, 58px);
  border-radius: calc(var(--radius) + 8px);
  background: var(--green-deep);
  box-shadow: var(--shadow);
  color: #fffdf7;
  text-align: center;
}

.clock-card::after {
  position: absolute;
  right: -80px;
  bottom: -110px;
  width: 280px;
  height: 280px;
  border: 40px solid rgba(255, 255, 255, 0.05);
  border-radius: 50%;
  content: "";
}

.date-display,
.period-status {
  position: relative;
  z-index: 1;
  margin-bottom: 0;
  color: rgba(255, 253, 247, 0.72);
  font-weight: 700;
}

.clock-display {
  position: relative;
  z-index: 1;
  display: block;
  margin: 10px 0 12px;
  font-size: clamp(4.8rem, 18vw, 11.5rem);
  font-variant-numeric: tabular-nums;
  font-weight: 850;
  line-height: 0.9;
  letter-spacing: -0.065em;
}

.next-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 22px;
  padding: clamp(22px, 4vw, 34px);
  border: 1px solid var(--line);
  border-left: 7px solid var(--gold);
  border-radius: var(--radius);
  background: rgba(255, 253, 247, 0.9);
  box-shadow: 0 12px 34px rgba(38, 45, 40, 0.08);
}

.next-label {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.next-card h2 {
  margin-bottom: 5px;
  font-size: clamp(1.5rem, 4vw, 2.3rem);
}

.next-time {
  margin-bottom: 0;
  color: var(--green);
  font-size: 1.1rem;
  font-weight: 850;
}

.countdown-wrap {
  display: grid;
  gap: 3px;
  min-width: 220px;
  text-align: right;
}

.countdown-wrap span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.countdown-wrap strong {
  font-size: clamp(2rem, 5vw, 3.6rem);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
}

.monitor-controls {
  display: flex;
  gap: 14px;
}

.primary-button,
.secondary-button {
  min-height: 58px;
  padding: 0 24px;
  border-radius: 14px;
  font-weight: 850;
}

.primary-button {
  flex: 1 1 60%;
  background: var(--green);
  box-shadow: 0 12px 26px rgba(20, 92, 78, 0.2);
  color: white;
}

.primary-button.active {
  background: var(--danger);
}

.secondary-button {
  flex: 1 1 40%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--green-deep);
}

.monitor-note {
  margin: -8px 0 0;
  padding: 14px 16px;
  border: 2px solid #c62828;
  border-left: 7px solid #b71c1c;
  border-radius: 14px;
  background: #ffebee;
  color: #b71c1c;
  font-size: 1rem;
  font-weight: 900;
  line-height: 1.65;
  box-shadow: 0 8px 20px rgba(183, 28, 28, 0.12);
}

.monitor-note.background-audio-active::before {
  content: "●";
  color: #17855b;
  margin-right: 0.45rem;
}

.settings-card {
  margin-top: clamp(38px, 7vw, 76px);
  padding: clamp(22px, 5vw, 46px);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 6px);
  background: rgba(255, 253, 247, 0.92);
  box-shadow: var(--shadow);
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 20px;
  margin-bottom: 26px;
}

.section-heading h2 {
  margin-bottom: 0;
  font-size: clamp(1.9rem, 4vw, 3rem);
}

.text-button {
  min-height: 42px;
  padding: 5px 0;
  background: transparent;
  color: var(--green);
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.weekday-fieldset {
  margin: 0 0 26px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-strong);
}

.weekday-fieldset legend {
  padding: 0 7px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.weekday-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}

.weekday-grid label {
  position: relative;
}

.weekday-grid input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.weekday-grid span {
  display: grid;
  place-items: center;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--muted);
  font-weight: 850;
  cursor: pointer;
}

.weekday-grid input:checked + span {
  border-color: var(--green);
  background: var(--green);
  color: white;
}

.weekday-grid input:focus-visible + span {
  outline: 4px solid rgba(194, 138, 44, 0.35);
  outline-offset: 3px;
}

.schedule-head,
.schedule-row {
  display: grid;
  grid-template-columns: 58px minmax(90px, 1fr) minmax(130px, 1fr) minmax(130px, 1fr) 58px;
  gap: 12px;
  align-items: center;
}

.schedule-head {
  padding: 0 14px 8px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 900;
}

.schedule-rows {
  display: grid;
  gap: 10px;
}

.schedule-row {
  position: relative;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
}

.schedule-row.has-error {
  border-color: rgba(161, 59, 50, 0.55);
}

.schedule-row input[type="text"],
.schedule-row input[type="time"] {
  width: 100%;
  min-height: 48px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  font-weight: 750;
}

.enabled-cell {
  display: grid;
  place-items: center;
}

.period-enabled {
  width: 24px;
  height: 24px;
  accent-color: var(--green);
}

.delete-period-button {
  min-height: 44px;
  padding: 0;
  background: transparent;
  color: var(--danger);
  font-size: 0.84rem;
  font-weight: 800;
}

.row-error {
  grid-column: 2 / -1;
  display: none;
  margin: -4px 0 0;
  color: var(--danger);
  font-size: 0.82rem;
  font-weight: 700;
}

.schedule-row.has-error .row-error {
  display: block;
}

.mobile-label {
  display: none;
}

.schedule-message {
  min-height: 1.4em;
  margin: 12px 2px 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.schedule-message.error {
  color: var(--danger);
  font-weight: 750;
}

.schedule-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 22px;
  margin-top: 20px;
}

.small-button {
  flex: 0 0 auto;
  min-height: 48px;
}

.volume-control {
  display: grid;
  grid-template-columns: auto minmax(130px, 240px) 48px;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.volume-control input {
  width: 100%;
  accent-color: var(--green);
}

.volume-control output {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.usage-note {
  margin: 20px auto 0;
  padding: 18px 22px;
  border-left: 4px solid var(--gold);
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.7;
}

.usage-note strong {
  color: var(--ink);
}

.usage-note p {
  margin: 5px 0 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

body.chime-flash .clock-card {
  animation: chime-flash 1s ease-out;
}

@keyframes chime-flash {
  0% { box-shadow: 0 0 0 0 rgba(194, 138, 44, 0.75), var(--shadow); }
  100% { box-shadow: 0 0 0 24px rgba(194, 138, 44, 0), var(--shadow); }
}

@media (max-width: 720px) {
  .page-shell {
    width: min(100% - 24px, 1100px);
    padding-top: 24px;
  }

  .topbar {
    min-height: 60px;
    padding-right: 12px;
    padding-left: 12px;
  }

  .back-link,
  .sync-pill,
  .language-button {
    font-size: 0.78rem;
  }

  .sync-pill,
  .language-button {
    min-height: 38px;
    padding: 6px 10px;
  }

  .clock-card {
    padding-right: 16px;
    padding-left: 16px;
  }

  .clock-display {
    font-size: clamp(4.1rem, 24vw, 7rem);
  }

  .next-card {
    align-items: end;
  }

  .countdown-wrap {
    min-width: 0;
  }

  .countdown-wrap strong {
    font-size: clamp(1.8rem, 7vw, 2.7rem);
  }

  .schedule-head {
    display: none;
  }

  .schedule-row {
    grid-template-columns: 38px minmax(72px, 0.8fr) minmax(102px, 1fr) minmax(102px, 1fr);
    gap: 8px;
    padding: 10px;
  }

  .delete-period-button {
    grid-column: 2 / -1;
    justify-self: end;
    min-height: 30px;
  }

  .row-error {
    grid-column: 2 / -1;
  }

  .mobile-label {
    display: block;
    margin: 0 0 4px 2px;
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 800;
  }

  .schedule-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .volume-control {
    grid-template-columns: auto 1fr 44px;
  }
}

@media (max-width: 500px) {
  .topbar {
    flex-wrap: wrap;
  }

  .topbar-actions {
    gap: 6px;
  }

  .hero {
    gap: 16px;
  }

  .hero-copy > p:last-child {
    line-height: 1.55;
  }

  .clock-card {
    border-radius: 18px;
  }

  .date-display,
  .period-status {
    font-size: 0.84rem;
  }

  .next-card {
    display: grid;
    gap: 14px;
    border-left-width: 5px;
  }

  .countdown-wrap {
    text-align: left;
  }

  .monitor-controls {
    flex-direction: column;
    gap: 9px;
  }

  .primary-button,
  .secondary-button {
    flex-basis: auto;
    width: 100%;
  }

  .settings-card {
    padding: 18px 12px;
  }

  .section-heading {
    align-items: start;
    flex-direction: column;
    gap: 6px;
  }

  .weekday-fieldset {
    padding: 12px;
  }

  .weekday-grid {
    gap: 5px;
  }

  .weekday-grid span {
    min-height: 40px;
    border-radius: 8px;
  }

  .schedule-row {
    grid-template-columns: 34px minmax(62px, 0.8fr) minmax(88px, 1fr) minmax(88px, 1fr);
    gap: 5px;
  }

  .schedule-row input[type="text"],
  .schedule-row input[type="time"] {
    min-height: 44px;
    padding: 6px;
    font-size: 0.82rem;
  }
}

@media (orientation: landscape) and (max-height: 560px) {
  .topbar {
    position: static;
  }

  .page-shell {
    padding-top: 16px;
  }

  .hero {
    grid-template-columns: minmax(0, 1.4fr) minmax(300px, 0.8fr);
    align-items: stretch;
  }

  .hero-copy {
    grid-column: 1 / -1;
  }

  .clock-card {
    display: grid;
    align-content: center;
    min-height: 250px;
    padding: 20px;
  }

  .clock-display {
    font-size: clamp(4.8rem, 12vw, 8rem);
  }

  .next-card {
    display: grid;
    align-content: center;
  }

  .monitor-controls,
  .monitor-note {
    grid-column: 1 / -1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
