:root {
  --red: #e24b4a;
  --blue: #4a90e2;
  --green: #4caf50;
  --orange: #f5a623;
  --purple: #7f77dd;
  --teal: #1d9e75;
  --pink: #d4537e;
  --gray: #777777;
  --text: #1e2933;
  --muted: #52616b;
  --line: #d7dee5;
  --focus: #15548f;
  --bg: #ffffff;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans CJK KR", system-ui, sans-serif;
}

button {
  font: inherit;
}

.app-shell {
  width: 100vw;
  height: 100vh;
  display: grid;
  grid-template-rows: 80px 1fr 56px;
  background: #fff;
}

.app-header,
.app-footer {
  display: flex;
  align-items: center;
  padding: 0 24px;
  background: #fff;
  border-bottom: 2px solid var(--line);
}

.app-footer {
  justify-content: space-between;
  border-top: 2px solid var(--line);
  border-bottom: 0;
  font-size: 19px;
}

.header-left,
.header-right {
  width: 190px;
  display: flex;
  align-items: center;
}

.header-right {
  justify-content: flex-end;
  gap: 14px;
}

h1 {
  flex: 1;
  margin: 0;
  text-align: center;
  font-size: 34px;
  line-height: 1.2;
}

.version {
  font-size: 16px;
  color: var(--muted);
}

.back-button {
  width: 100px;
  height: 60px;
  border: 2px solid var(--gray);
  border-radius: 12px;
  background: #fff;
  color: var(--gray);
  font-size: 34px;
  font-weight: 800;
}

.utility-button,
.confirm-button {
  min-width: 74px;
  height: 46px;
  border: 2px solid var(--blue);
  border-radius: 10px;
  background: #fff;
  color: #15548f;
  font-size: 18px;
  font-weight: 700;
}

.screen {
  position: relative;
  min-width: 1024px;
  min-height: 0;
  padding: 16px 24px 18px;
  opacity: 0;
  transition: opacity 0.3s ease;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.screen.is-ready {
  opacity: 1;
}

.home-grid,
.mode-grid,
.card-grid,
.yes-no-grid,
.correct-actions,
.small-answer-row {
  display: grid;
  gap: 16px;
}

.home-grid {
  width: min(1680px, 88vw, 100%);
  min-height: min(620px, calc(100vh - 80px - 56px - 34px));
  margin: 0 auto;
  grid-template-columns: repeat(3, minmax(260px, 1fr));
  align-content: center;
  align-items: stretch;
}

.home-grid .card {
  min-height: clamp(320px, 44vh, 500px);
  padding: 32px;
  gap: 18px;
}

.home-grid .card-emoji {
  font-size: clamp(80px, 8vh, 108px);
}

.home-grid .card-text {
  font-size: clamp(36px, 4.6vh, 52px);
}

.mode-grid {
  width: 920px;
  margin: 0 auto;
  grid-template-columns: repeat(2, 1fr);
}

.card-grid {
  width: min(1040px, 100%);
  margin: 0 auto;
}

.two-column {
  grid-template-columns: repeat(2, minmax(320px, 1fr));
  align-content: center;
}

.favorite-grid {
  width: min(820px, 100%);
  grid-template-columns: repeat(2, minmax(240px, 1fr));
  grid-auto-rows: minmax(clamp(120px, 18vh, 180px), auto);
  gap: 12px;
  align-content: center;
}

.favorite-grid .card {
  min-height: clamp(120px, 18vh, 180px);
  padding: 14px 16px;
  gap: 6px;
  font-size: clamp(24px, 3.2vh, 32px);
}

.favorite-grid .card-emoji {
  font-size: clamp(34px, 5vh, 46px);
}

.favorite-grid .card-subtext {
  font-size: clamp(16px, 2.3vh, 19px);
}

.category-grid {
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  grid-auto-rows: minmax(150px, 1fr);
  min-height: min(500px, calc(100vh - 80px - 56px - 42px));
  align-content: center;
}

.item-grid {
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  align-content: center;
}

.card {
  min-width: 200px;
  min-height: 120px;
  padding: 20px;
  border: 2px solid var(--blue);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  font-size: 32px;
  font-weight: 800;
  line-height: 1.2;
  cursor: pointer;
  transition: transform 0.2s ease, background-color 0.2s ease, border-width 0.1s ease;
}

.card:active {
  transform: scale(0.95);
}

.card:focus-visible,
.back-button:focus-visible,
.utility-button:focus-visible,
.confirm-button:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 4px;
  background: #f8fbff;
}

.card:disabled {
  cursor: not-allowed;
  opacity: 0.58;
  background: #f5f5f5;
}

.red { border-color: var(--red); }
.blue { border-color: var(--blue); }
.green { border-color: var(--green); }
.orange { border-color: var(--orange); }
.purple { border-color: var(--purple); }
.teal { border-color: var(--teal); }
.pink { border-color: var(--pink); }
.gray { border-color: var(--gray); }

.red:focus-visible,
.red.is-speaking { background: #fff4f4; }
.blue:focus-visible,
.blue.is-speaking { background: #f1f7ff; }
.green:focus-visible,
.green.is-speaking { background: #f1fff2; }
.orange:focus-visible,
.orange.is-speaking { background: #fff8eb; }
.purple:focus-visible,
.purple.is-speaking { background: #f5f4ff; }
.teal:focus-visible,
.teal.is-speaking { background: #effff9; }
.pink:focus-visible,
.pink.is-speaking { background: #fff2f7; }
.gray:focus-visible,
.gray.is-speaking { background: #f7f7f7; }

.card.is-speaking {
  border-width: 5px;
}

.card-emoji {
  font-size: 46px;
}

.card-text {
  word-break: keep-all;
}

.card-subtext,
.card-badge {
  font-size: 19px;
  font-weight: 700;
  color: var(--muted);
}

.card-badge {
  color: #555;
}

.big-word .card-text,
.answer-card .card-text {
  font-size: 54px;
}

.notice-host {
  min-height: 52px;
  margin-bottom: 14px;
}

.speech-notice {
  width: min(1040px, 100%);
  min-height: 48px;
  margin: 0 auto;
  padding: 12px 18px;
  border: 2px solid var(--blue);
  border-radius: 10px;
  background: #f8fbff;
  font-size: 22px;
  font-weight: 800;
}

.guide-text,
.guess-line {
  width: min(1040px, 100%);
  margin: 0 auto 16px;
  font-size: 25px;
  font-weight: 800;
  text-align: center;
}

.secret-panel,
.correct-panel {
  width: 760px;
  margin: 0 auto;
  text-align: center;
}

.secret-panel h2,
.correct-panel h2 {
  margin: 12px 0;
  font-size: 56px;
}

.secret-panel p {
  margin: 0 0 26px;
  font-size: 28px;
}

.lock {
  font-size: 96px;
}

.action-card {
  width: 520px;
  margin: 0 auto;
}

/* v1.6: 추측 모드 카테고리 확인 화면 */
.guess-ask-panel {
  width: min(760px, 100%);
  margin: 0 auto;
  text-align: center;
  padding-top: 24px;
}

.guess-ask-emoji {
  font-size: 120px;
  line-height: 1;
  margin-bottom: 12px;
}

.guess-ask-question {
  margin: 12px 0 8px;
  font-size: 56px;
  font-weight: 800;
}

.guess-ask-hint {
  margin: 0 0 32px;
  font-size: 22px;
  color: #555;
}

.guess-ask-actions {
  display: flex;
  gap: 24px;
  justify-content: center;
  align-items: stretch;
  flex-wrap: wrap;
}

.guess-ask-actions .action-card {
  width: 320px;
  min-height: 140px;
  margin: 0;
}

.guess-answer-panel h2 {
  font-size: 60px;
}

/* v1.7: 출제 모드 진행 화면 — 상태 표시 + 두 결말 버튼만 */
.host-progress-panel {
  width: min(760px, 100%);
  margin: 0 auto;
  text-align: center;
  padding-top: 24px;
}

.host-progress-emoji {
  font-size: 120px;
  line-height: 1;
  margin-bottom: 12px;
}

.host-progress-title {
  margin: 12px 0 8px;
  font-size: 56px;
  font-weight: 800;
}

.host-progress-hint {
  margin: 0 0 32px;
  font-size: 22px;
  color: #555;
}

.host-progress-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.host-progress-actions .host-correct-btn {
  width: 420px;
  min-height: 160px;
  font-size: 32px;
}

.host-progress-actions .host-giveup-btn {
  width: 280px;
  min-height: 80px;
  font-size: 20px;
}

/* v1.7: 출제 모드 정답 화면 분기 톤 */
.host-result-correct h2 {
  font-size: 64px;
  color: #1f7a3a;
}

.host-result-gave_up h2 {
  font-size: 52px;
  color: #555;
  font-weight: 700;
}

.private-answer {
  position: absolute;
  top: 12px;
  left: 24px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #333;
  font-size: 16px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.private-answer-value {
  min-width: 44px;
}

.private-answer-toggle {
  width: 24px;
  height: 24px;
  margin-left: 3px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
  line-height: 1;
}

.private-answer-toggle:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.host-answer-main {
  width: 100%;
  min-height: min(500px, calc(100vh - 80px - 56px - 34px));
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.answer-display {
  width: 760px;
  min-height: 92px;
  margin: 0 auto 22px;
  display: grid;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #fff;
  font-size: 46px;
  font-weight: 900;
}

.yes-no-grid {
  width: 760px;
  margin: 0 auto 18px;
  grid-template-columns: repeat(2, 1fr);
}

.wide-action {
  width: 760px;
  margin: 0 auto;
}

.guess-top {
  width: min(1120px, 100%);
  margin: 0 auto 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.correct-card {
  margin: 18px auto;
  padding: 30px;
  border: 5px solid var(--green);
  border-radius: 14px;
  font-size: 64px;
  font-weight: 900;
  background: #f1fff2;
}

.correct-actions {
  grid-template-columns: repeat(2, 1fr);
}

.empty-state {
  width: 760px;
  margin: 0 auto;
  padding: 32px;
  border: 2px solid var(--line);
  border-radius: 12px;
  font-size: 27px;
  font-weight: 800;
  text-align: center;
  line-height: 1.45;
}

.guess-play {
  width: min(1120px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 14px;
}

.guess-section {
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  background: #fff;
}

.guess-section h2 {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 20px;
  font-weight: 900;
}

.guess-history-section {
  background: #f7f9fb;
}

.history-list {
  min-height: 42px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 18px;
  font-weight: 800;
}

.history-chip {
  max-width: 100%;
  padding: 7px 10px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-chip.answer {
  background: #eef4f8;
}

.current-question {
  margin: 0 0 12px;
  font-size: 28px;
  font-weight: 900;
  text-align: center;
}

.large-answer-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(200px, 1fr));
  gap: 14px;
}

.large-answer-row .card,
.confirm-answer-card {
  min-height: 86px;
  font-size: 28px;
}

.guess-candidate-section {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 12px 16px;
  align-items: start;
}

.guess-candidate-section h2 {
  grid-column: 1 / -1;
}

.guess-item-grid {
  width: 100%;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 12px;
}

.guess-item-grid .card {
  min-width: 0;
  min-height: 86px;
  padding: 12px;
  font-size: 24px;
}

.guess-item-grid .card-emoji {
  font-size: 30px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.88);
}

.hidden {
  display: none;
}

.rest-modal {
  width: 720px;
  padding: 36px;
  border: 4px solid var(--green);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.18);
  text-align: center;
}

.rest-modal h2 {
  margin: 0 0 14px;
  font-size: 48px;
}

.rest-modal p {
  margin: 0 0 26px;
  font-size: 26px;
  font-weight: 700;
}

.modal-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

@media (max-height: 820px) {
  .card {
    min-height: 108px;
    font-size: 28px;
    padding: 16px;
  }

  .card-emoji {
    font-size: 38px;
  }

  .secret-panel,
  .correct-panel {
    margin-top: 0;
  }

  .correct-card {
    padding: 24px;
  }

  .two-column {
    gap: 12px;
  }

  .two-column .card {
    min-height: 96px;
  }

  .category-grid {
    min-height: 430px;
    gap: 12px;
  }

  .guide-text {
    margin-bottom: 12px;
  }

  .guess-play {
    gap: 10px;
  }

  .guess-section {
    padding: 10px;
  }

  .large-answer-row .card,
  .confirm-answer-card,
  .guess-item-grid .card {
    min-height: 80px;
  }

  .current-question {
    font-size: 24px;
  }
}

/* ===================================
   v1.9: 즐겨찾기 편집 영역
   =================================== */

/* 헤더 우측 [+] 버튼 — CSV 버튼과 동일한 utility-button 스타일 차용 */
.fav-header-add {
  min-width: 46px;
  width: 46px;
  height: 46px;
  border: 2px solid var(--green);
  border-radius: 10px;
  background: #fff;
  color: var(--green);
  font-size: 26px;
  font-weight: 800;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.fav-header-add:hover:not(.is-disabled):not([disabled]) {
  background: #f3fbf4;
}

.fav-header-add:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.fav-header-add.is-disabled,
.fav-header-add[disabled] {
  border-color: var(--line);
  color: var(--muted);
  background: #f6f7f8;
  cursor: not-allowed;
}

/* 빈 상태 안내 */
.fav-empty-state {
  margin: 0 auto;
  padding: 36px 28px;
  width: min(640px, 92%);
  background: #f9fafb;
  border: 2px dashed var(--line);
  border-radius: 16px;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.7;
  text-align: center;
}

/* 카드 영역: 빠른 표현(.card-grid.two-column)과 동일 레이아웃 활용.
   fav-edit-grid는 추가 보정만(편집/삭제 버튼 자리 확보). */
.fav-edit-grid .fav-card {
  position: relative;
}

.fav-card-tools {
  position: absolute;
  right: 8px;
  bottom: 8px;
  display: flex;
  gap: 6px;
}

.fav-tool-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.92);
  border: 2px solid var(--line);
  border-radius: 10px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.fav-tool-btn:hover { background: #fff; border-color: var(--focus); }
.fav-tool-btn:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
.fav-del-btn { color: var(--red); font-weight: 700; font-size: 22px; }

/* 모달 */
.fav-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 40, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.fav-modal {
  width: min(520px, 92vw);
  max-height: 92vh;
  overflow-y: auto;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.25);
  padding: 24px 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.fav-modal-title {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
}

.fav-modal-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 16px;
  color: var(--muted);
  font-weight: 600;
}

.fav-modal-input {
  width: 100%;
  padding: 12px 14px;
  font-size: 20px;
  border: 2px solid var(--line);
  border-radius: 10px;
  font-family: inherit;
}

.fav-modal-input:focus {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
  border-color: var(--focus);
}

.fav-emoji-current-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  color: var(--muted);
}

.fav-emoji-current {
  font-size: 28px;
  padding: 2px 6px;
}

.fav-emoji-direct {
  flex: 0 0 100px;
  padding: 8px 10px;
  font-size: 20px;
  border: 2px solid var(--line);
  border-radius: 8px;
  font-family: inherit;
}

.fav-emoji-palette {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.fav-emoji-pick {
  width: 100%;
  aspect-ratio: 1 / 1;
  font-size: 26px;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.fav-emoji-pick:hover { background: #f4f7fb; }
.fav-emoji-pick.is-selected { border-color: var(--focus); background: #eaf2fb; }

.fav-modal-error {
  padding: 8px 10px;
  background: #fdecec;
  border: 1px solid var(--red);
  border-radius: 8px;
  color: var(--red);
  font-size: 15px;
}

.fav-modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 6px;
}

.fav-modal-btn {
  min-width: 110px;
  padding: 12px 18px;
  font-size: 18px;
  font-weight: 700;
  border-radius: 10px;
  border: 2px solid transparent;
  cursor: pointer;
}

.fav-modal-save { background: var(--green); color: #fff; }
.fav-modal-save:hover { background: #3da041; }
.fav-modal-delete { background: var(--red); color: #fff; }
.fav-modal-delete:hover { background: #c43d3c; }
.fav-modal-cancel { background: #fff; color: var(--text); border-color: var(--line); }
.fav-modal-cancel:hover { background: #f4f7fb; }

.fav-modal-btn:focus { outline: 3px solid var(--focus); outline-offset: 2px; }

.fav-confirm-preview {
  margin: 4px 0 8px;
  padding: 14px 16px;
  background: #f9fafb;
  border-radius: 10px;
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
}
