@font-face {
  font-family: 'Digital7Mono';
  src: url('font/digital-7-mono.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}

:root {
  --font: 'IBM Plex Mono', monospace;
  --font-digit: 'Digital7Mono', monospace;
  --size: 15px;
  --ink: #1a1a1a;
  --text: #59554d;
  --bg: #eae7de;
  --sheet: #fffdf8;
  --light: #faf9f6;
  --line: #1a1a1a;
  --muted: #9a9a9a;
}

* {
  box-sizing: border-box;
}

::selection {
  background: var(--ink);
  color: var(--light);
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--size);
  font-weight: 400;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

button, textarea, input {
  font-family: var(--font);
  font-size: var(--size);
  font-weight: 400;
  line-height: 1.7;
  color: var(--text);
}

#app {
  height: 100dvh;
  width: 100%;
}

.screen {
  display: none;
  height: 100%;
  width: 100%;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.screen::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

.screen.active {
  display: flex;
}

/* ---------- shared ---------- */

.stack {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(20px, 4dvh, 56px);
  text-align: center;
  padding: 24px;
}

button {
  background: none;
  border: 1px solid var(--ink);
  padding: 10px 18px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

button:hover {
  background: var(--ink);
  color: var(--light);
}

button.primary {
  background: var(--ink);
  color: var(--light);
}

button.primary:hover {
  opacity: 0.8;
  background: var(--ink);
  color: var(--light);
}

.oct {
  border-radius: 0;
  clip-path: polygon(
    10px 0,
    calc(100% - 10px) 0,
    100% 10px,
    100% calc(100% - 10px),
    calc(100% - 10px) 100%,
    10px 100%,
    0 calc(100% - 10px),
    0 10px
  );
}

/* ---------- screen 1: timer ---------- */

#screen-timer {
  flex-direction: column;
}

#screen-timer .stack {
  flex: 1;
  width: 100%;
  margin: 0;
}

.app-footer {
  flex-shrink: 0;
  padding: 24px;
  text-align: center;
}

.app-footer p {
  margin: 0;
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
}

.app-footer a {
  color: inherit;
  font-size: inherit;
  font-weight: inherit;
  text-decoration: none;
  padding-bottom: 2px;
  border-bottom: 1px dotted var(--muted);
}

.app-footer a:hover {
  color: var(--text);
  border-bottom-color: var(--text);
}

.glyph {
  display: inline-block;
  vertical-align: -1px;
  color: var(--muted);
}

.timer-input {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

#minutes-value {
  font-size: clamp(64px, min(40dvw, calc(32dvh - 60px)), 260px);
  line-height: 1;
}

.unit {
  color: var(--muted);
}

.keypad {
  container-type: inline-size;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  width: min(1400px, calc(100dvw - 48px), calc(195dvh - 323px));
  min-width: 560px;
}

.key {
  aspect-ratio: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: none;
  border: 1px solid var(--ink);
  border-radius: 0;
  font-size: clamp(20px, 13cqw, 110px);
  line-height: 1;
  clip-path: polygon(30% 0%, 70% 0%, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0% 70%, 0% 30%);
}

.key:not(.digital) {
  font-size: clamp(11px, 5.5cqw, 28px);
}

@media (max-width: 640px) {
  .keypad {
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    width: min(1400px, calc(100dvw - 48px), calc(49dvh - 90px));
    min-width: 320px;
  }

  .key {
    font-size: clamp(24px, 22cqw, 90px);
  }

  .key:not(.digital) {
    font-size: clamp(12px, 9cqw, 26px);
  }
}

.digital {
  font-family: var(--font-digit);
}

/* ---------- screen 2: letter ---------- */

#screen-letter {
  flex-direction: column;
}

.letter-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 24px 32px;
  flex-shrink: 0;
}

#time-left {
  grid-column: 2;
  justify-self: center;
  position: relative;
  z-index: 10;
  font-size: clamp(48px, 12dvw, 88px);
  line-height: 1;
  letter-spacing: 0.05em;
}

#finish-btn {
  grid-column: 3;
  justify-self: end;
}

.letter-pages {
  display: contents;
}

.letter-paper {
  flex: 1;
  min-height: 320px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--sheet);
  padding: 40px 32px 24px;
  max-width: 640px;
}

@media (max-width: 640px) {
  .letter-header {
    padding: 16px 20px;
  }

  #finish-btn {
    padding: 6px 12px;
  }

  .letter-paper {
    width: calc(100% - 24px);
    padding: 24px 20px 16px;
  }
}

.letter-meta {
  color: var(--muted);
  margin-bottom: 24px;
  user-select: none;
}

.letter-body {
  flex: 1;
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  overflow-y: hidden;
  background: none;
  padding: 0;
}

.letter-body::placeholder {
  color: var(--muted);
}

.page-nav {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 16px 0 32px;
}

.page-number {
  flex-shrink: 0;
  margin-top: auto;
  padding-top: 16px;
  color: var(--muted);
  text-align: center;
  user-select: none;
}

.nav-btn {
  padding: 10px 24px;
  visibility: hidden;
}

.nav-btn.visible {
  visibility: visible;
}

/* ---------- screen 3: done ---------- */

#screen-done .stack {
  gap: 40px;
}

#screen-done .stack button {
  width: min(280px, 70dvw);
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: clamp(18px, 3dvw, 26px);
  clip-path: polygon(30% 0%, 70% 0%, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0% 70%, 0% 30%);
}
