:root {
  --bg: #f5f6f7;
  --surface: #ffffff;
  --text: #16181b;
  --text-2: #5c626a;
  --text-3: #9aa0a8;
  --line: #e3e6ea;
  --line-strong: #c9ced5;
  --accent: #5a6b7e;
  --accent-soft: #eef1f5;
  --graphite: #1e2228;

  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Meiryo", "Segoe UI", sans-serif;
  --font-num: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", "Segoe UI", Roboto, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --gutter: 20px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-feature-settings: "palt" 1;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

p,
h1,
h2,
h3 {
  margin: 0;
}

button {
  font: inherit;
  color: inherit;
}

/* ---------- Main layout ---------- */

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  padding:
    env(safe-area-inset-top)
    max(var(--gutter), env(safe-area-inset-right))
    env(safe-area-inset-bottom)
    max(var(--gutter), env(safe-area-inset-left));
}

.header {
  flex: none;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  height: 60px;
  border-bottom: 1px solid var(--line);
}

.title {
  grid-column: 2;
  text-align: center;
  font-size: 19.2px;
  font-weight: 600;
  letter-spacing: 0.08em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  grid-column: 3;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-right: -10px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
}

.icon-btn:hover {
  color: var(--text);
  background: rgba(22, 24, 27, 0.04);
}

.icon-btn:focus-visible,
.done-btn:focus-visible,
.credit:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 12px 0;
  overflow-y: auto;
}

/* ---------- Time list ---------- */

.list {
  --count: 1;
  --row-max: 112px;
  --row-h: min(var(--row-max), calc((100dvh - 290px) / var(--count)));

  flex: 0 1 calc(var(--count) * var(--row-max));
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin: auto 0;
  padding: 0;
  list-style: none;
}

.list[data-count="1"],
.list[data-count="2"] {
  --row-max: 140px;
}

.row {
  flex: 1 1 0;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 2px;
  border-bottom: 1px solid var(--line);
}

.row:last-child {
  border-bottom: 0;
}

.row__label {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}

.row__index {
  flex: none;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  color: var(--accent);
}

.row__text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.row__name {
  font-size: 22.1px;
  font-weight: 500;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row__code {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row__time {
  flex: none;
  font-family: var(--font-num);
  font-size: clamp(24px, min(10.5vw, calc(var(--row-h) * 0.5)), 68px);
  font-weight: 300;
  line-height: 1;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums lining-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
  color: var(--text);
}

.row__sep {
  display: inline-block;
  padding: 0 0.04em;
  color: var(--text-3);
  transform: translateY(-0.06em);
}

.noscript {
  padding: 24px 0;
  text-align: center;
  color: var(--text-2);
  font-size: 14px;
}

/* ---------- Status footer ---------- */

.status {
  flex: none;
  padding: 14px 0 16px;
  border-top: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.9;
  letter-spacing: 0.14em;
  text-align: center;
  color: var(--text-2);
}

.status__ok {
  color: var(--accent);
  font-weight: 600;
}

/* ---------- Settings overlay ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: stretch;
  justify-content: center;
  background: rgba(22, 24, 27, 0.32);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.16s ease, visibility 0.16s ease;
}

.overlay.is-open {
  opacity: 1;
  visibility: visible;
}

.sheet {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  background: var(--surface);
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  outline: none;
}

.sheet__head {
  flex: none;
  padding: 22px var(--gutter) 16px;
  border-bottom: 1px solid var(--line);
}

.sheet__title {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.sheet__desc {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-2);
  letter-spacing: 0.04em;
}

.sheet__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 4px var(--gutter) 20px;
}

.region {
  margin-top: 18px;
}

.region__title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--text-2);
}

.region__en {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.14em;
  color: var(--text-3);
}

.pref-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  column-gap: 12px;
}

.pref {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
  letter-spacing: 0.04em;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.pref input {
  -webkit-appearance: none;
  appearance: none;
  flex: none;
  display: grid;
  place-content: center;
  width: 20px;
  height: 20px;
  margin: 0;
  border: 1.5px solid var(--line-strong);
  border-radius: 5px;
  background: var(--surface);
  cursor: pointer;
}

.pref input::before {
  content: "";
  width: 10px;
  height: 5px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: translateY(-1px) rotate(-45deg);
  opacity: 0;
}

.pref input:checked {
  border-color: var(--accent);
  background: var(--accent);
}

.pref input:checked::before {
  opacity: 1;
}

.pref input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.pref__name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.is-full .pref input:not(:checked) {
  border-color: var(--line);
}

.is-full .pref input:not(:checked) + .pref__name {
  color: var(--text-3);
}

.sheet__foot {
  flex: none;
  padding: 14px var(--gutter) 0;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.notice {
  display: none;
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid #dde2e8;
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  background: var(--accent-soft);
  font-size: 13px;
  line-height: 1.65;
  letter-spacing: 0.02em;
  color: var(--text);
  white-space: pre-line;
  text-wrap: pretty;
  word-break: auto-phrase;
}

.notice.is-show {
  display: block;
}

.sheet__actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.counter {
  display: flex;
  align-items: baseline;
  gap: 2px;
  color: var(--text-2);
}

.counter__label {
  margin-right: 10px;
  font-size: 13px;
  letter-spacing: 0.06em;
}

.counter__value {
  font-family: var(--font-num);
  font-size: 26px;
  font-weight: 400;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.counter__max {
  font-family: var(--font-num);
  font-size: 15px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.done-btn {
  min-width: 148px;
  height: 50px;
  padding: 0 24px;
  border: 0;
  border-radius: 10px;
  background: var(--graphite);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.2em;
  cursor: pointer;
}

.done-btn:hover {
  background: #2c323a;
}

.done-btn:active {
  background: #11141a;
}

.credit {
  display: block;
  width: max-content;
  margin: 6px auto 0;
  padding: 12px 16px 14px;
  font-size: 15.6px;
  letter-spacing: 0.16em;
  color: var(--text-2);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.3em;
}

.credit:hover {
  color: var(--accent);
}

/* ---------- Responsive ---------- */

@media (max-width: 359px) {
  :root {
    --gutter: 16px;
  }

  .pref-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 640px) {
  :root {
    --gutter: 28px;
  }

  .header {
    height: 72px;
  }

  .title {
    font-size: 21.6px;
  }

  .row__name {
    font-size: 24.7px;
  }

  .row__code {
    font-size: 10.5px;
  }

  .row__index {
    font-size: 11px;
  }

  .overlay {
    align-items: center;
    padding: 24px;
  }

  .sheet {
    max-width: 580px;
    height: min(880px, 100%);
    padding: 0;
    border-radius: 16px;
    box-shadow: 0 24px 64px rgba(22, 24, 27, 0.18), 0 2px 8px rgba(22, 24, 27, 0.06);
    overflow: hidden;
  }

  .pref-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  .overlay {
    transition: none;
  }
}
