/* 깜빡 · blue and yellow, phone first. On wider screens the app stays a phone-width column. */
:root {
  --bg: #1E31B8;
  --panel: #16248C;
  --deep: #101C78;
  --line: #3346D0;
  --btn-line: #5466D6;
  --lamp: #FFD23F;
  --paper: #F4F6FF;
  --soft: #AEB8F5;
  --hint: #D5DBFF;
  --placeholder: #8F9BE8;
  --fut: #3B4CC4;
  --fut-cur: #6F7EE0;
  --box-done: #2A3BA8;
  --box-todo: #4757D6;
  --coral: #FF8A7A;
  --mint: #7DF0C6;
  --red: #C42B17;

  --font: 'IBM Plex Sans KR', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  --display: 'Do Hyeon', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  --logo: 'Gasoek One', 'Black Han Sans', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--paper);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
}

button, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
button:disabled { opacity: 0.45; cursor: default; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--lamp); outline-offset: 2px; }

.noscroll { scrollbar-width: none; -ms-overflow-style: none; }
.noscroll::-webkit-scrollbar { display: none; }

.app {
  position: relative;
  max-width: 480px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ---- Shared controls ---- */

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 10px;
  border: 2px solid var(--btn-line);
  border-radius: 999px;
  background: transparent;
  color: var(--paper);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}
.pill[aria-pressed="true"], .pill.on { background: var(--paper); border-color: var(--paper); color: var(--deep); }
.pill.small { min-height: 32px; padding: 0 12px; font-size: 12px; }
.pill.mono { padding: 0; font-family: var(--mono); font-weight: 500; }
.pill .i-stop { display: none; }
.pill.on .i-stop { display: inline; }
.pill.on .i-play, .pill.on .i-speaker { display: none; }
.pill-group { display: inline-flex; gap: 4px; }
.lang .pill.small { min-height: 30px; padding: 0 10px; font-size: 11px; letter-spacing: 0.04em; }

.btn-lamp {
  border: 0;
  border-radius: 12px;
  background: var(--lamp);
  color: var(--deep);
  font-size: 15px;
  font-weight: 700;
}
.btn-lamp.big { min-height: 54px; border-radius: 999px; font-family: var(--display); font-size: 21px; font-weight: 400; }

.text-link {
  min-height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--soft);
  font-size: 14px;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.count { font-family: var(--mono); font-size: 12px; color: var(--soft); }

.notice { margin: 0; font-size: 13px; color: var(--soft); }
.notice.err, .notice.coral { color: var(--coral); }

/* ---- 받은 신호 and 보내기 ---- */

.top {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(18px + var(--safe-top)) 20px 8px;
}
.logo { font-family: var(--logo); font-size: 26px; line-height: 1; color: var(--lamp); }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.home-main {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 20px 28px;
}

.pane { display: flex; flex-direction: column; gap: 6px; }
#recvPane { gap: 30px; }

.paste { display: flex; flex-direction: column; gap: 6px; }

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 34px;
}
.label-row label { font-size: 13px; color: var(--soft); }

.field { position: relative; }
.field-input {
  display: block;
  width: 100%;
  height: 92px;
  resize: none;
  border: 2px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  color: var(--paper);
}
.field-input::placeholder { color: var(--placeholder); }
/* 16px keeps iPhones from zooming in when the box is tapped. */
.mono-input { padding: 14px 86px 14px 16px; font-family: var(--mono); font-size: 16px; line-height: 1.5; }
/* The paste box's placeholder matches 보내기's ("보낼 말을 써 보세요"); pasted Morse stays smaller and monospaced. */
.mono-input::placeholder { font-family: var(--font); font-size: 20px; font-weight: 500; }
.msg-input { padding: 14px 86px 14px 16px; font-size: 20px; font-weight: 500; line-height: 1.45; }
.btn-lamp.in-field { position: absolute; right: 10px; bottom: 10px; min-width: 64px; height: 40px; padding: 0 14px; }

/* 받은 기록 */
.inbox { display: flex; flex-direction: column; gap: 10px; }
.inbox-head { display: flex; align-items: baseline; gap: 8px; }
.inbox-head h2 { margin: 0; font-size: 15px; font-weight: 700; }
.inbox-count { font-family: var(--mono); font-size: 12px; color: var(--soft); }
.inbox-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.inbox-item {
  display: flex;
  align-items: stretch;
  border: 2px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  overflow: hidden;
}
.inbox-open {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 9px;
  padding: 12px 4px 12px 14px;
  border: 0;
  background: transparent;
  text-align: left;
}
.mini-boxes { display: flex; align-items: center; gap: 3px; max-width: 100%; overflow: hidden; }
.mini {
  flex: none;
  width: 22px;
  height: 26px;
  border: 1.5px solid var(--box-todo);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--display);
  font-size: 15px;
  line-height: 1;
}
.mini.known { background: var(--box-done); border-color: var(--box-done); }
.mini-gap { flex: none; width: 6px; }
.mini-more { flex: none; padding-left: 2px; color: var(--soft); font-size: 13px; }
.inbox-meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--soft); }
.chip {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border: 1.5px solid var(--btn-line);
  border-radius: 999px;
  color: var(--paper);
  font-size: 12px;
  font-weight: 700;
}
.chip.new { background: var(--lamp); border-color: var(--lamp); color: var(--deep); }
.chip.perfect { background: var(--mint); border-color: var(--mint); color: var(--deep); }
.chip.solved { border-color: var(--soft); }
.inbox-del {
  flex: none;
  width: 48px;
  border: 0;
  background: transparent;
  color: var(--soft);
  display: flex;
  align-items: center;
  justify-content: center;
}
.inbox-empty {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 14px 16px 4px;
  border: 2px dashed var(--line);
  border-radius: 16px;
}
.inbox-empty p { margin: 0; font-size: 14px; color: var(--soft); }

/* 보내기 */
.btn-row { display: flex; gap: 6px; margin-top: 8px; }
.btn-row .pill { flex: 1 1 0; padding: 0 4px; }
/* 복사했어요: the button turns yellow and its icon becomes a check for a moment. */
.pill.copied { background: var(--lamp); border-color: var(--lamp); color: var(--deep); }
.pill .i-check { display: none; }
.pill.copied .i-check { display: inline; }
.pill.copied .i-main { display: none; }
.preview-card {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 12px 16px;
  min-height: 60px;
  margin-top: 8px;
  padding: 16px;
  border: 2px solid var(--line);
  border-radius: 24px;
  background: var(--deep);
}
.pv-char { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.pv-ch { font-size: 13px; font-weight: 700; }
.pv-code { display: flex; align-items: center; gap: 6px; height: 10px; }
.pv-part { display: flex; align-items: center; gap: 3px; }
.pv-sym { display: block; width: 8px; height: 8px; border-radius: 4px; background: var(--lamp); }
.pv-sym.dash { width: 20px; }
.pv-space { display: block; width: 2px; height: 26px; background: var(--line); }
.pv-empty { margin: 0; font-size: 14px; color: var(--soft); }
.preview-card.playing .pv-sym { background: #4A5CCF; }
.preview-card.playing .pv-ch { color: var(--soft); }
.preview-card.playing .pv-char.on .pv-sym { background: var(--lamp); }
.preview-card.playing .pv-char.on .pv-ch { color: var(--paper); }
.copy-fail { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.copy-fail p { margin: 0; font-size: 13px; color: var(--coral); }
.copy-fail-text {
  max-height: 96px;
  overflow-y: auto;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--panel);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  word-break: break-all;
  -webkit-user-select: all;
  user-select: all;
}
#tryItBtn { align-self: center; margin-top: 8px; }

.home-foot { display: flex; justify-content: center; margin-top: 36px; }
.home-foot a { padding: 8px; color: var(--soft); font-size: 12px; text-decoration: none; }
.home-foot a:hover { text-decoration: underline; }

.tabs {
  flex: none;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 8px 16px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: var(--panel);
}
.tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 54px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: var(--soft);
  font-size: 13px;
  font-weight: 700;
}
.tab[aria-current="page"] { background: var(--box-done); color: var(--paper); }
.tab-dot { position: absolute; top: 8px; left: calc(50% + 8px); width: 10px; height: 10px; border-radius: 50%; background: var(--lamp); }

.toast {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: calc(92px + var(--safe-bottom));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 8px 8px 16px;
  border-radius: 14px;
  background: var(--paper);
  color: var(--deep);
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 6px 20px rgba(8, 12, 60, 0.35);
}
.toast-btn { min-height: 40px; padding: 0 14px; border: 0; border-radius: 10px; background: var(--deep); color: var(--paper); font-size: 14px; font-weight: 700; }

/* ---- Banner ad (320 × 50): under the logo on 받은 신호 and 보내기, above the progress bar on 풀기 ---- */

.ad { flex: none; display: flex; justify-content: center; margin: 0 16px 6px; }
.ad ins.adsbygoogle { display: inline-block; width: 320px; height: 50px; }
/* AdSense had nothing to show: give the space back. */
.ad:has(ins[data-ad-status="unfilled"]) { display: none; }
.ad-solve { margin-top: calc(10px + var(--safe-top)); }
/* Keep clear space between the banner and the ✕ under it, so it isn't tapped by mistake. */
.ad:not([hidden]) + .solve-top { padding-top: 8px; }
.ad-ph {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 320px;
  height: 50px;
  border: 1.5px dashed var(--btn-line);
  border-radius: 8px;
  color: var(--soft);
  font-size: 12px;
}

/* ---- 풀기 ---- */

/* Holding the pad or tapping fast must never start a text selection or the long-press menu.
   Only the decoded message on the results card can be selected (to copy it). */
.solve { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.solve .result-message { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }

.solve-top {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(14px + var(--safe-top)) 16px 4px;
}
.icon-btn {
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--soft);
  display: flex;
  align-items: center;
  justify-content: center;
}
.segs { flex: 1 1 auto; display: flex; gap: 4px; }
.seg { flex: 1 1 0; height: 6px; border-radius: 3px; background: var(--panel); overflow: hidden; }
.seg-fill { display: block; width: 0; height: 100%; background: var(--lamp); transition: width 160ms ease-out; }
.solve-top .count { flex: none; min-width: 44px; text-align: right; font-size: 13px; }

.play-view {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 12px 16px calc(20px + var(--safe-bottom));
}
.play-mid { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; justify-content: center; }

.slots-wrap { position: relative; flex: none; }
.slots {
  max-height: 102px;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
}
/* A thin scroll indicator for messages longer than two rows of letters. Drawn by hand so it
   shows on phones too, where native scrollbars only flash while scrolling. */
.scroll-ind {
  position: absolute;
  top: 2px;
  right: 0;
  bottom: 2px;
  width: 3px;
  border-radius: 2px;
  background: rgba(174, 184, 245, 0.2);
  pointer-events: none;
}
.scroll-thumb { position: absolute; top: 0; left: 0; right: 0; border-radius: 2px; background: var(--soft); }
.slot {
  width: 40px;
  height: 48px;
  border: 2px solid var(--box-todo);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--paper);
  font-family: var(--display);
  font-size: 25px;
}
.slot.done { background: var(--box-done); border-color: var(--box-done); }
.slot.cur { border-color: var(--lamp); }
.slot.ask { color: var(--lamp); }
.slot.play { background: var(--lamp); border-color: var(--lamp); color: var(--deep); }
.slot-gap { display: block; width: 10px; }
@keyframes blink { 0% { opacity: 0; } 30% { opacity: 1; } 45% { opacity: 0.25; } 100% { opacity: 1; } }
.pop { animation: blink 420ms ease-out both; }

.hint {
  flex: none;
  height: 22px;
  margin: 22px 0 0;
  overflow: hidden;
  color: var(--hint);
  font-size: 15px;
  font-weight: 500;
  line-height: 22px;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hint.err { color: var(--coral); }
.hint.good { color: var(--mint); }

.track { position: relative; flex: none; margin: 12px -16px 0; padding: 4px 0; overflow-x: auto; overflow-y: hidden; }
.track-inner { display: flex; align-items: flex-start; gap: 6px; width: max-content; padding: 0 6px; }
.tile {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 6px 8px 9px;
  border: 2px solid transparent;
  border-radius: 12px;
}
.tile.cur { background: var(--panel); border-color: var(--lamp); }
.tile-letter {
  min-width: 26px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 2px solid transparent;
  color: var(--paper);
  font-family: var(--display);
  font-size: 23px;
}
.tile.blank .tile-letter { border-bottom-color: var(--line); }
.tile-letter.ask { color: var(--lamp); }
.tile-code { display: flex; align-items: center; gap: 6px; height: 12px; }
.tile-part { display: flex; align-items: center; gap: 3px; }
.tile-gap { flex: none; display: block; width: 10px; }

.sym {
  position: relative;
  display: block;
  width: 10px;
  height: 12px;
  overflow: hidden;
  border: 2px solid var(--fut);
  border-radius: 6px;
  background: var(--fut);
}
.sym.dash { width: 26px; }
.sym.in-cur { border-color: var(--fut-cur); background: var(--fut-cur); }
.sym.keyed { border-color: var(--lamp); background: var(--lamp); }
.sym.target { border-color: var(--lamp); background: transparent; }
.sym.target.err { border-color: var(--coral); }
.sym.sounding { box-shadow: 0 0 0 2px var(--paper); }
.sym-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--lamp); }
.sym.keyed .sym-fill { width: 100%; }
/* The gauge: the dot or dash being keyed fills over its press time (set from JS). */
.sym.pressing .sym-fill { width: 100%; transition-property: width; transition-timing-function: linear; }
.sym.bad .sym-fill { background: var(--coral); }

.tools { flex: none; display: flex; gap: 6px; margin: 18px 0 12px; }
.tools > .pill { flex: 1 1 0; }
.tools > .pill.stop { flex: 1.3 1 0; }
.speeds { flex: 3 1 0; display: flex; gap: 4px; }
.speeds .pill { flex: 1 1 0; }

/* The key or the code table. Shorter phones get a shorter pad. */
.input-area { flex: none; height: clamp(240px, 40vh, 300px); display: flex; flex-direction: column; }

.pad {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  overflow: hidden;
  border: 0;
  border-radius: 28px;
  background: var(--panel);
  box-shadow: inset 0 0 0 2px var(--line);
  color: var(--paper);
  font-family: var(--display);
  font-size: 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  transition: background 60ms, box-shadow 60ms;
}
.pad.lit { background: var(--lamp); box-shadow: inset 0 0 0 2px var(--lamp); color: var(--deep); }
.tapkey { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; touch-action: none; }
.pad-dots {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(circle, var(--box-done) 1.5px, transparent 2px);
  background-position: center;
  background-size: 18px 18px;
}
.pad.lit .pad-dots { opacity: 0; }
.pad-sym {
  position: relative;
  display: block;
  width: 34px;
  height: 34px;
  overflow: hidden;
  border: 3px solid var(--lamp);
  border-radius: 17px;
  transition: width 120ms ease-out;
}
.pad-sym.dash { width: 104px; }
.pad-sym.err { border-color: var(--coral); }
.pad.lit .pad-sym { border-color: var(--deep); }
.pad-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--deep); }
.pad-sym.pressing .pad-fill { width: 100%; transition-property: width; transition-timing-function: linear; }
.pad-sym.bad .pad-fill { background: var(--red); }
.pad-label { position: relative; }

.code-table { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
.table-tabs { flex: none; display: flex; gap: 6px; }
.table-tabs .pill { flex: 1 1 0; min-height: 40px; }
.table-grid {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  align-content: start;
  gap: 6px;
}
.table-grid.small { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.cell {
  min-width: 0;
  height: 54px;
  padding: 0;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--paper);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.table-grid.small .cell { height: 44px; gap: 5px; }
.cell-j { font-family: var(--display); font-size: 21px; line-height: 1; }
/* Punctuation reads better in the monospace face, and six-symbol codes need smaller pills. */
.table-grid.small .cell-j { font-family: var(--mono); font-size: 17px; font-weight: 500; }
.cell-code { display: flex; align-items: center; gap: 2px; height: 5px; }
.cell-code i { display: block; width: 5px; height: 5px; border-radius: 3px; background: currentColor; }
.cell-code i.dash { width: 9px; }
.table-grid.small .cell-code { gap: 1.5px; }
.table-grid.small .cell-code i { width: 4px; height: 4px; }
.table-grid.small .cell-code i.dash { width: 7px; }
.cell.hot { background: var(--lamp); border-color: var(--lamp); color: var(--deep); }
.cell.bad { border-color: var(--coral); color: var(--coral); }
.cell-break { grid-column: 1 / -1; height: 2px; }

.done-view {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 26px 16px calc(24px + var(--safe-bottom));
}
/* Title, letter boxes and card sit together, centred in the screen. The letter boxes show as many
   rows as fit and scroll beyond that; the auto margins keep the top reachable if it all overflows. */
.done-title { margin: auto 0 0; color: var(--lamp); font-family: var(--display); font-size: 38px; font-weight: 400; text-align: center; }
.done-view .slots-wrap { flex: 0 1 auto; min-height: 0; display: flex; flex-direction: column; }
.done-view .slots { flex: 0 1 auto; min-height: 0; max-height: none; }
.result-card {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: auto;
  padding: 22px 20px;
  border: 2px solid var(--lamp);
  border-radius: 24px;
  background: var(--deep);
}
.result-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.result-label { color: var(--soft); font-size: 14px; }
.result-stat { color: var(--lamp); font-size: 14px; font-weight: 700; text-align: right; }
.result-message { font-family: var(--display); font-size: 38px; line-height: 1.2; overflow-wrap: anywhere; }
.result-message.long { font-size: 26px; }
.result-row { display: flex; gap: 8px; }
.result-row .pill { flex: 1 1 0; min-height: 46px; border-color: var(--line); font-size: 14px; }
.result-row .pill.outline-paper { border-color: var(--paper); }

/* Shorter phones (iPhone SE and the like): tighter spacing so the 부호표 fits without scrolling. */
@media (max-height: 720px) {
  .slots { max-height: 48px; } /* one row of letters; the scroll indicator shows there's more */
  .hint { margin-top: 16px; }
  .tools { margin: 12px 0 10px; }
  .cell { height: 46px; gap: 5px; }
  .cell-j { font-size: 19px; }
  .table-grid.small .cell { height: 40px; }
}

/* Decorative motion only; the press gauges keep their timing because they tell you how long to hold. */
@media (prefers-reduced-motion: reduce) {
  .pop { animation: none; }
  .seg-fill, .pad-sym, .pad, .pad-dots { transition: none; }
}
