:root {
  color-scheme: light;
  font-family: system-ui, sans-serif;
  color: #1c2940;
  background: #f5f6fa;
  --navy: #14233a;
  --ink: #1c2940;
  --muted: #53647f;
  --line: #d8dfe9;
  --primary: #344b93;
  --primary-dark: #263a77;
  --surface: #fff;
  --danger: #9b2841;
  --sleep: #344b93;
  --nap: #206b62;
  --awake: #f0c777;
  --half: #e6daf4;
  --drowsy: #6b3c70;
  font-size: 16px;
}
* { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button, select { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 3px solid #7167d9; outline-offset: 3px; }
.skip-link { position: fixed; top: .5rem; left: .5rem; z-index: 2; padding: .7rem; color: var(--navy); background: #fff; transform: translateY(-180%); }
.skip-link:focus { transform: translateY(0); }

.site-header { color: #fff; background: var(--navy); }
.header-inner { margin: auto; max-width: 80rem; min-height: 4.6rem; padding: .75rem 1.5rem; display: flex; align-items: center; gap: 1.5rem; }
.brand { display: flex; align-items: center; gap: .65rem; margin-right: auto; font-size: 1.06rem; font-weight: 720; white-space: nowrap; }
.moon { width: 1.27rem; height: 1.27rem; display: inline-block; flex: 0 0 auto; border-radius: 50%; box-shadow: inset -.41rem -.22rem 0 .02rem #c3caff; transform: rotate(-17deg); }
nav { display: flex; gap: .25rem; }
nav button, .logout { min-height: 44px; border: 0; padding: .55rem .85rem; background: transparent; color: #e2e8fb; border-radius: .45rem; }
nav button[aria-current], nav button:hover, .logout:hover { background: #2a3d5d; color: #fff; }
.logout { border: 1px solid #607290; font-size: .875rem; }

.page, .notice { max-width: 56rem; margin-inline: auto; }
.page { padding: 2.5rem 1.5rem 3rem; }
.wide-page { max-width: 80rem; }
.page-heading { margin-bottom: 1.75rem; }
.heading-actions { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
h1 { margin: 0 0 .5rem; font-size: clamp(1.55rem, 5vw, 2.35rem); font-weight: 750; letter-spacing: -.035em; line-height: 1.17; }
h2 { margin: 0 0 .65rem; font-size: 1.35rem; }
p { line-height: 1.55; }
.page-heading p, .hint, .result-status { margin: 0; color: var(--muted); }
.notice { margin-top: 1rem; padding: .8rem 1rem; border-radius: .55rem; background: #e8f3ed; color: #1b573c; font-weight: 650; }
.notice.error { background: #fce8ed; color: #81233b; }

.card { min-inline-size: 0; margin: 0 0 1.35rem; background: var(--surface); border: 1px solid var(--line); border-radius: .85rem; padding: 1rem 1.15rem 1.2rem; }
.card > legend { padding: 0 .4rem; font-weight: 730; font-size: 1.1rem; }
.fields { display: grid; gap: .95rem; }
.fields.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.fields.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
label { display: block; font-size: .91rem; font-weight: 660; }
input, select, textarea {
  background: #fbfcfe;
  border: 1px solid #aebbd0;
  border-radius: .45rem;
  width: 100%;
  min-width: 0;
  min-height: 46px;
  margin-top: .35rem;
  padding: .55rem .7rem;
}
input[type="time"], input[type="date"] { font-variant-numeric: tabular-nums; }
input[readonly] { background: #eef1f7; }
textarea { display: block; resize: vertical; }
.date-following { align-self: end; margin: 0; padding: 0 0 .7rem; color: var(--muted); }
.date-following strong { color: var(--ink); }
.button { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; text-align: center; min-height: 46px; border: 1px solid transparent; padding: .55rem .95rem; border-radius: .52rem; font-size: .93rem; line-height: 1.2; font-weight: 690; text-decoration: none; }
.button:disabled { opacity: .58; cursor: wait; }
.primary { background: var(--primary); color: #fff; }
.primary:hover { background: var(--primary-dark); }
.secondary { background: #edf1fb; border-color: #ced8ef; color: #2a417f; }
.secondary:hover { background: #e3eafa; }
.text-button { color: var(--primary-dark); background: transparent; }
.text-button:hover { text-decoration: underline; }
.danger { color: var(--danger); background: #fff0f3; border-color: #efc7d1; }
.danger:hover { background: #ffe1e7; }
.event-toolbar, .dictation, .form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .8rem; }
.event-toolbar > p { margin: 0; color: var(--muted); font-size: .91rem; }
#event-details { margin-top: .9rem; }
.hint { font-size: .91rem; }
.event-row { min-inline-size: 0; border: 1px solid var(--line); border-radius: .55rem; margin: .95rem 0; padding: .6rem .8rem; }
.event-row legend { padding: 0 .3rem; color: var(--muted); font-size: .9rem; font-weight: 650; }
.event-row .remove-event { color: var(--danger); margin-top: .35rem; }
.dictation { margin-top: .6rem; }
.microphone { position: relative; display: inline-block; width: .63rem; height: .93rem; border: 2px solid currentColor; border-radius: .4rem; }
.microphone::after { content: ""; position: absolute; left: 50%; bottom: -.31rem; height: .25rem; border-left: 2px solid currentColor; transform: translateX(-50%); }

.signin { min-height: calc(100vh - 4.6rem); padding: 3.5rem 1.25rem; display: grid; place-items: start center; background: linear-gradient(165deg, #ecf0fb, #f5f6fa 65%); }
.signin-card { background: #fff; border: 1px solid var(--line); border-radius: 1.1rem; padding: clamp(1.35rem, 6vw, 3rem); width: min(100%, 32rem); text-align: center; }
.signin-card p { color: var(--muted); margin-bottom: 1.45rem; }
.signin-symbol { width: 3.25rem; height: 3.25rem; margin: 0 auto 1.15rem; border-radius: .8rem; display: grid; place-items: center; background: var(--navy); }
.signin-symbol .moon { transform: rotate(-17deg) scale(1.25); }

.period { display: flex; align-items: end; gap: .75rem; flex-wrap: wrap; }
.period label { flex: 1 1 8rem; max-width: 13rem; }
.export-buttons { display: flex; flex-wrap: wrap; gap: .45rem; }
.result-status { margin: 0 0 .75rem; font-size: .94rem; }
.history-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .65rem; }
.history-item { display: flex; justify-content: space-between; align-items: center; gap: .55rem; padding: .8rem 1rem; background: #fff; border: 1px solid var(--line); border-radius: .6rem; }
.history-item strong { display: block; }
.history-item p { margin: .2rem 0 0; color: var(--muted); font-size: .9rem; }

.agenda-scroll { overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: .65rem; }
.agenda-table { width: 100%; min-width: 65rem; table-layout: fixed; border-collapse: collapse; background: #fff; font-size: .875rem; }
.agenda-table caption { text-align: left; padding: .75rem 1rem; font-weight: 700; }
.agenda-table th, .agenda-table td { border: 1px solid #bbc6d7; padding: .4rem; overflow-wrap: anywhere; }
.agenda-table thead th { background: #eaf0fb; }
.agenda-table thead th:nth-child(2), .agenda-table .timeline-cell { padding: 0; }
.agenda-table td:nth-child(n+3):nth-child(-n+5) { text-align: center; }
.agenda-table .remarks-cell { white-space: pre-wrap; }
.agenda-table .date-col { width: 10%; }
.agenda-table .time-col { width: 53%; }
.agenda-table .rating-col { width: 6.5%; }
.agenda-table .notes-col { width: 17.5%; }
.agenda-table .empty-cell { text-align: center; padding: 1rem; }
.timeline { display: block; width: 100%; overflow: visible; }
.chart-head { font: 11px system-ui, sans-serif; fill: #344660; }
.chart-line { stroke: #aab5c8; stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-line.major { stroke: #73829a; }
.chart-night { fill: #eef2fa; }
.chart-awakening { fill: var(--awake); }
.chart-sleep { fill: var(--sleep); }
.chart-nap { fill: var(--nap); }
.chart-half-sleep { fill: var(--half); }
.chart-drowsiness { fill: #f0dfed; }
.chart-text { fill: var(--ink); font: 700 14px system-ui, sans-serif; }
.chart-text.drowsiness { fill: var(--drowsy); }
.chart-text.half-sleep { fill: #513571; }
.legend { list-style: none; margin: 0; padding: .25rem; display: flex; flex-wrap: wrap; gap: .3rem .85rem; color: var(--ink); font-size: .8rem; }
.legend li { display: flex; align-items: center; gap: .25rem; }
.legend span { display: inline-grid; place-content: center; width: 1.1rem; min-height: .78rem; font-weight: 750; }
.legend .sleep { background: var(--sleep); }
.legend .nap { background: var(--nap); }
.legend .awakening { background: var(--awake); }
.legend .half-sleep { background: var(--half); }
.legend .drowsiness { color: var(--drowsy); background: #f0dfed; }

dialog { color: var(--ink); width: min(calc(100% - 2rem), 27rem); border: 1px solid var(--line); border-radius: .8rem; padding: 1.4rem; }
dialog::backdrop { background: #13243a90; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: .6rem; justify-content: end; }

@media (max-width: 620px) {
  .header-inner { gap: .35rem .75rem; padding: .55rem .85rem; flex-wrap: wrap; }
  nav { order: 3; width: 100%; }
  nav button { flex: 1 1 0; padding-inline: .25rem; }
  .logout { min-height: 44px; padding-inline: .48rem; }
  .page { padding: 1.6rem .85rem 2rem; }
  .page-heading { margin-bottom: 1.25rem; }
  .notice { margin-inline: .85rem; }
  .card { padding-inline: .75rem; }
  .fields.three { grid-template-columns: minmax(0, 1fr); gap: .65rem; }
  .event-row .fields.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .event-row .fields.three label:first-child { grid-column: 1 / -1; }
  .form-actions .primary { width: 100%; }
  .heading-actions { align-items: start; flex-direction: column; }
  .period label { max-width: none; }
  .export-buttons { width: 100%; }
  .export-buttons .button { flex: 1; }
}
@media (max-width: 350px) {
  .fields.two { grid-template-columns: minmax(0, 1fr); }
  .date-following { padding: 0; }
}
@page { size: A4 landscape; margin: 9mm; }
@media print {
  :root { background: #fff; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .site-header, .notice, .skip-link, .export-panel, .result-status, dialog, #signin, #entry, #history { display: none !important; }
  .page { max-width: none; margin: 0; padding: 0; }
  .page-heading { margin-bottom: 2mm; }
  .page-heading h1 { font-size: 16pt; }
  .page-heading p { display: none; }
  .agenda-scroll { border: 0; overflow: visible; border-radius: 0; }
  .agenda-table { width: 100%; min-width: 0; font-size: 8pt; }
  .agenda-table th, .agenda-table td { padding: 1mm; }
  .agenda-table caption, .legend { font-size: 7.5pt; }
  .agenda-table caption { padding: 1mm 0; }
  .agenda-table tr { break-inside: avoid; }
  .agenda-table thead { display: table-header-group; }
  .agenda-table tfoot { display: table-footer-group; }
}
