:root {
  --bg: #f6f3ee;
  --card: #ffffff;
  --text: #1f1d1a;
  --muted: #6d675f;
  --line: #e4ded4;
  --today: #fff6e0;
  --arrive: #2f7d4f;
  --leave: #c25a2c;
  --accent: #2c5d8f;
  --error: #b3261e;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a18;
    --card: #262421;
    --text: #f1ede6;
    --muted: #a8a196;
    --line: #3a3732;
    --today: #3a3222;
    --arrive: #3c9a63;
    --leave: #d46c3c;
    --accent: #7fb0e0;
    --error: #ff8a80;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
}

h1 { font-size: 1.3rem; margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }

/* login */
.login { padding-top: 15vh; text-align: center; }
.login form { display: grid; gap: 12px; max-width: 260px; margin: 24px auto 0; }
.login label { color: var(--muted); }
.login input {
  font-size: 1.6rem; text-align: center; letter-spacing: 0.3em;
  padding: 10px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--text);
}
.primary {
  padding: 12px; border: 0; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 600;
}
@media (prefers-color-scheme: dark) { .primary { color: #10233a; } }

/* header */
.top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 16px; }
.week-nav { display: flex; align-items: center; gap: 4px; font-weight: 600; }
.icon-btn {
  width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 50%;
  background: var(--card); font-size: 1.4rem; line-height: 1;
}
.link { flex-basis: 100%; text-align: right; background: none; border: 0; color: var(--accent); padding: 0; }

/* today */
.today { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin-bottom: 16px; }
.today-label { margin: 0 0 12px; color: var(--muted); }
.punch { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.punch button {
  border: 0; border-radius: 14px; padding: 22px 8px; font-size: 1.25rem; font-weight: 700; color: #fff;
  transition: transform 0.08s;
}
.punch button:active { transform: scale(0.97); }
.arrive { background: var(--arrive); }
.leave { background: var(--leave); }
.today-status { margin: 12px 0 0; min-height: 1.4em; text-align: center; }

/* days */
.day-head, .day {
  display: grid;
  grid-template-columns: 4.6rem 1fr 1fr 3.2rem;
  gap: 8px;
  align-items: center;
}
.day-head { font-size: 0.85rem; color: var(--muted); padding: 0 12px 4px; }
.day-head span:last-child, .day .hours { text-align: right; }
.days { list-style: none; margin: 0 0 16px; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.day { padding: 10px 12px; border-top: 1px solid var(--line); }
.day:first-child { border-top: 0; }
.day.is-today { background: var(--today); }
.day .name { font-weight: 600; line-height: 1.15; }
.day .name small { display: block; font-weight: 400; color: var(--muted); font-size: 0.8rem; }
.day input {
  width: 100%; min-width: 0; font: inherit; font-size: 0.95rem;
  padding: 6px 4px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--text);
}
.day input:invalid, .day.bad input { border-color: var(--error); }
.day .hours { font-variant-numeric: tabular-nums; }
.day.bad .hours { color: var(--error); }

/* total */
.total {
  width: 100%; display: grid; justify-items: center; gap: 2px;
  padding: 18px; border: 2px solid var(--accent); border-radius: 16px; background: var(--card);
}
.total:active { transform: scale(0.99); }
.total-label { color: var(--muted); }
.total-value { font-size: 2.8rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.total-hint { color: var(--accent); font-size: 0.9rem; }

.error { color: var(--error); min-height: 1.2em; margin: 10px 0 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 380px) {
  .day-head, .day { grid-template-columns: 3.6rem 1fr 1fr 2.8rem; gap: 6px; }
  .day input { font-size: 0.85rem; padding: 6px 2px; }
}
