/* Paperlogy is bundled with the app so the home-screen app works offline. */
@font-face { font-family: "Paperlogy"; src: url("fonts/Paperlogy-4Regular.woff2") format("woff2"); font-weight: 100 500; font-style: normal; font-display: swap; }
@font-face { font-family: "Paperlogy"; src: url("fonts/Paperlogy-7Bold.woff2") format("woff2"); font-weight: 600 900; font-style: normal; font-display: swap; }

/* Light tokens are the base; app.js sets <html data-theme="dark|light"> from the setting (자동 follows the system). */
:root {
  --bg: #f5f3ee;
  --fg: #1d1b18;
  --muted: #77726a;
  --faint: #bdb7ad;
  --accent: #d9822b;
  --lunch: #3aa65a;
  --card: #ebe7df;
  --sun: #d6453d;
  --sat: #3a6fd8;
  --today-fg: #fff;
  --track: #e2ded5;
  --panel: #ffffff;
  --line: #d8d3c9;
  --dim: 1;
  --shift-x: 0px;
  --shift-y: 0px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #000;
  --fg: #ece7dd;
  --muted: #8f8a81;
  --faint: #4a4741;
  --accent: #ffad42;
  --lunch: #4cc46e;
  --card: #121212;
  --sun: #ff6b5e;
  --sat: #6f9dff;
  --today-fg: #000;
  --track: #222;
  --panel: #161616;
  --line: #333;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: var(--win-w, 100%);
  height: var(--win-h, 100%);
  background: var(--bg);
  color: var(--fg);
  font-family: "Paperlogy", -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
  touch-action: manipulation;
  transition: background-color 0.6s ease, color 0.6s ease;
}

h2 { margin: 0; font-weight: 500; }

/* Two columns (60% / 40%) sized from the viewport height so nothing ever needs scrolling. */
/* --app-w/--app-h/--vh come from app.js: iPhone home-screen apps launched in landscape report a wrong
   viewport height until rotated, so the real screen size is measured and used instead of 100% / vh. */
/* Not position: fixed. iOS clips fixed layers to its (wrong, too short) layout viewport after a landscape
   launch, which cut off the bottom of the calendar; a normally positioned box is drawn over the whole screen. */
#face {
  position: absolute;
  top: var(--app-y, 0);
  left: var(--app-x, 0);
  width: var(--app-w, 100%);
  height: var(--app-h, 100%);
  /* Same margin top/bottom and left/right: iPhone's landscape insets are uneven (home indicator at the bottom only),
     so the larger inset is used on both sides and the content stays vertically centred. */
  --pad-y: max(calc(5 * var(--vh, 1vh)), env(safe-area-inset-top), env(safe-area-inset-bottom));
  --pad-x: max(calc(3 * var(--vw, 1vw)), env(safe-area-inset-left), env(safe-area-inset-right));
  padding: var(--pad-y) var(--pad-x);
  display: grid;
  grid-template-columns: minmax(0, 6fr) minmax(0, 4fr);
  gap: calc(4 * var(--vw, 1vw));
  opacity: var(--dim);
  transform: translate(var(--shift-x), var(--shift-y));
  transition: opacity 1.5s ease, transform 2s ease;
}
section { min-width: 0; min-height: 0; }

/* Detail strip under the main screen, only in tall windows. Same width, side padding and columns as #face. */
.detail {
  position: absolute;
  left: var(--app-x, 0);
  top: calc(var(--app-y, 0px) + var(--app-h, 100%));
  width: var(--app-w, 100%);
  height: var(--detail-h, 0px);
  padding: 0 var(--pad-x) var(--pad-y);
  --pad-y: calc(5 * var(--vh, 1vh));
  --pad-x: calc(3 * var(--vw, 1vw));
  display: grid;
  grid-template-columns: minmax(0, 6fr) minmax(0, 4fr);
  gap: calc(4 * var(--vw, 1vw));
  opacity: var(--dim);
  transform: translate(var(--shift-x), var(--shift-y));
  transition: opacity 1.5s ease, transform 2s ease;
}
.detail[hidden] { display: none; }
.detail > div { display: flex; flex-direction: column; gap: calc(2.5 * var(--vh, 1vh)); min-width: 0; min-height: 0; }
.hours { list-style: none; margin: 0; padding: calc(2.5 * var(--vh, 1vh)) 0; display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); flex: 1; min-height: 0; background: var(--card); border-radius: calc(3 * var(--vh, 1vh)); }
.hours li { display: flex; flex-direction: column; align-items: center; justify-content: space-evenly; min-width: 0; }
.hours li + li { border-left: 1px solid var(--line); }
.hours li.empty { grid-column: 1 / -1; color: var(--muted); font-size: calc(3.6 * var(--vh, 1vh)); border: 0; }
.hours .t { font-size: calc(3 * var(--vh, 1vh)); color: var(--muted); }
.hours li:first-child .t { color: var(--accent); font-weight: 700; }
.hours .i { font-size: calc(5.2 * var(--vh, 1vh)); line-height: 1; }
.hours .v { font-size: calc(4.2 * var(--vh, 1vh)); font-weight: 700; }
.hours .r { font-size: calc(2.8 * var(--vh, 1vh)); color: var(--sat); min-height: 1.2em; }
.facts { margin: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-auto-rows: 1fr; gap: calc(1.2 * var(--vw, 1vw)); flex: 1; min-height: 0; }
.facts div { background: var(--card); border-radius: calc(3 * var(--vh, 1vh)); display: flex; flex-direction: column; justify-content: center; align-items: center; gap: calc(1 * var(--vh, 1vh)); min-width: 0; }
.facts dt { font-size: calc(3 * var(--vh, 1vh)); color: var(--muted); }
.facts dd { margin: 0; font-size: calc(4.4 * var(--vh, 1vh)); font-weight: 700; white-space: nowrap; }
.facts small { font-size: 0.65em; font-weight: 400; color: var(--muted); }

.label { font-size: calc(4.4 * var(--vh, 1vh)); font-weight: 400; color: var(--muted); }
.head { display: flex; justify-content: space-between; align-items: baseline; gap: 1em; }

/* Left: weekly weather (Mon–Sat) on top, work-hours bar at the bottom. */
.left { display: flex; flex-direction: column; justify-content: space-between; gap: calc(5 * var(--vh, 1vh)); }
.weather { display: flex; flex-direction: column; gap: calc(2.5 * var(--vh, 1vh)); flex: 1; min-height: 0; }
.place-name { color: var(--faint); font-size: 0.85em; margin-left: 0.2em; }
.now { font-size: calc(4.4 * var(--vh, 1vh)); color: var(--muted); white-space: nowrap; }
.now b { color: var(--fg); font-weight: 700; }
.week { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: calc(1.2 * var(--vw, 1vw)); flex: 1; min-height: 0; }
.week li {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-evenly;
  padding: calc(1.5 * var(--vh, 1vh)) 0;
  border-radius: calc(2.5 * var(--vh, 1vh));
  background: var(--card);
  border: 2px solid transparent;
  font-variant-numeric: tabular-nums;
  min-width: 0;
}
.week li.empty { grid-column: 1 / -1; background: none; color: var(--muted); font-size: calc(4 * var(--vh, 1vh)); }
.week li.today { border-color: var(--accent); }
.week li.past { opacity: 0.45; }
.week .d { font-size: calc(5 * var(--vh, 1vh)); font-weight: 700; }
.week .today .d { color: var(--accent); }
.week .dt { font-size: calc(3 * var(--vh, 1vh)); color: var(--muted); }
.week .i { font-size: calc(7.5 * var(--vh, 1vh)); line-height: 1; }
.week .hi { font-size: calc(4.6 * var(--vh, 1vh)); font-weight: 700; }
.week .lo { font-size: calc(3.8 * var(--vh, 1vh)); color: var(--muted); }
.week .r { font-size: calc(3.2 * var(--vh, 1vh)); color: var(--sat); min-height: 1.2em; }

.work { display: flex; flex-direction: column; gap: calc(1.4 * var(--vh, 1vh)); }
.work-percent { font-size: calc(9 * var(--vh, 1vh)); font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.bar { position: relative; height: calc(3.4 * var(--vh, 1vh)); border-radius: calc(1.7 * var(--vh, 1vh)); background: var(--track); overflow: hidden; }
.bar-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent); transition: width 1s linear; }
.bar-lunch { position: absolute; top: 0; bottom: 0; background: var(--lunch); opacity: 0.45; }
.bar-lunch.passed, .work.lunch .bar-lunch { opacity: 1; }
.bar-now { position: absolute; top: 0; bottom: 0; width: 3px; margin-left: -1.5px; background: var(--fg); opacity: 0.8; }
.work.off .bar-now, .work.before .bar-now, .work.done .bar-now { display: none; }
.bar-labels { position: relative; height: calc(3.6 * var(--vh, 1vh)); font-size: calc(3.2 * var(--vh, 1vh)); color: var(--muted); font-variant-numeric: tabular-nums; }
.bar-labels span { position: absolute; top: 0; white-space: nowrap; }
#work-start { left: 0; }
#work-end { right: 0; }
.lunch-label { color: var(--lunch); transform: translateX(-50%); }
.work-detail { font-size: calc(4 * var(--vh, 1vh)); color: var(--fg); font-variant-numeric: tabular-nums; }
.work.lunch .work-detail { color: var(--lunch); }
.work.off .work-percent, .work.off .bar-fill { opacity: 0.4; }

/* Right: month calendar. */
/* Right column: clock, year-month, calendar with equal space between them (space-between).
   Glyph boxes carry blank space above/below the ink, so the nudges below were measured from screenshots:
   the clock's ink top sits on the ink top of the left column's first line, and the gaps clock→title→weekdays
   look equal. */
.right { display: flex; flex-direction: column; justify-content: space-between; }
.clock { display: flex; flex-direction: column; gap: calc(1.5 * var(--vh, 1vh)); font-size: min(calc(22 * var(--vh, 1vh)), calc(10 * var(--vw, 1vw))); }
.clock-head { justify-content: center; font-size: initial; }
.clock-head:has(.period:empty) { display: none; }
/* 24-hour mode: the digits are the first line, so pull their ink top up to the heading's ink top. */
.clock:has(.period:empty) .time { margin-top: -0.055em; }
.time {
  display: flex;
  justify-content: center;
  align-items: baseline;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.time .colon { margin: 0 0.1em; position: relative; top: -0.06em; }
.cal-title { font-size: calc(5.2 * var(--vh, 1vh)); font-weight: 700; text-align: center; line-height: 1; position: relative; top: -0.17em; }
.cal { margin-bottom: calc(-1.25 * var(--vh, 1vh)); width: 100%; border-collapse: collapse; table-layout: fixed; font-variant-numeric: tabular-nums; }
.cal th { font-size: calc(3.4 * var(--vh, 1vh)); font-weight: 400; color: var(--muted); padding-bottom: calc(0.8 * var(--vh, 1vh)); }
.cal tbody tr:last-child td { padding-bottom: 0; }
.cal td { text-align: center; font-size: calc(4.2 * var(--vh, 1vh)); padding: calc(0.2 * var(--vh, 1vh)) 0; }
.cal td span { display: inline-flex; align-items: center; justify-content: center; width: 1.7em; height: 1.7em; border-radius: 50%; padding-top: 0.08em; }
.cal .sun { color: var(--sun); }
.cal .sat { color: var(--sat); }
.cal td.today span { background: var(--accent); color: var(--today-fg); font-weight: 700; }

.notice {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(8px, env(safe-area-inset-bottom));
  max-width: calc(36 * var(--vw, 1vw));
  padding: 5px 12px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}
.notice[hidden] { display: none; }

.settings-button {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--fg);
  font: inherit;
  font-size: 15px;
}
.settings-button[hidden] { display: none; }

dialog {
  width: min(600px, calc(var(--win-w, 100vw) - 32px));
  max-height: calc(var(--win-h, 100vh) - 20px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  color: var(--fg);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.55); }

.panel { padding: 14px 20px; display: flex; flex-direction: column; gap: 8px; font-size: 15px; }
.panel h2 { font-size: 18px; font-weight: 600; }
/* The close button stays at the top: on iPhone in landscape the panel is taller than the screen. */
.panel-head {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: -14px -20px 0;
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.panel-head button { min-width: 72px; min-height: 40px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 32px; }
.row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }
.row input[type="range"] { width: 50%; accent-color: var(--accent); }
.seg { display: inline-flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.seg label { display: inline-flex; align-items: center; gap: 3px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 8px; }
.seg input { margin: 0; accent-color: var(--accent); }
.seg.days label { padding: 4px 6px; }
input[type="time"], input[type="search"] {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 8px;
  font: inherit;
}
.place { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px 10px; margin: 0; }
.place legend { padding: 0 4px; }
.place-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.place-actions input { flex: 1; min-width: 140px; }
.city-results { list-style: none; margin: 6px 0 0; padding: 0; }
.city-results button { width: 100%; text-align: left; margin-top: 4px; }
button { background: var(--bg); color: var(--fg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; font: inherit; }
button.primary { background: var(--accent); color: var(--today-fg); border-color: var(--accent); font-weight: 600; }
.actions { display: flex; justify-content: flex-end; }
.muted { color: var(--muted); font-size: 13px; margin: 0; }

/* Portrait: stack the columns. Landscape is the intended use. */
/* A phone held upright. Wider portrait windows (PC) keep the landscape layout, see fitViewport in app.js. */
@media (orientation: portrait) and (max-width: 599px) {
  #face { grid-template-columns: 1fr; grid-template-rows: 1fr auto; gap: calc(3 * var(--vh, 1vh)); }
  .label, .now, .cal th, .bar-labels, .week .dt, .week .r { font-size: calc(3.2 * var(--vw, 1vw)); }
  .week .d, .week .hi, .cal td, .work-detail { font-size: calc(3.8 * var(--vw, 1vw)); }
  .week .lo { font-size: calc(3.2 * var(--vw, 1vw)); }
  .week .i { font-size: calc(6 * var(--vw, 1vw)); }
  .work-percent { font-size: calc(8 * var(--vw, 1vw)); }
  .cal-title { font-size: calc(5 * var(--vw, 1vw)); }
  .time { font-size: calc(16 * var(--vw, 1vw)); }
  .bar { height: calc(2.4 * var(--vw, 1vw)); }
  .bar-labels { height: calc(4 * var(--vw, 1vw)); }
}
