:root {
  --primary-color: #2f4a40;
  --primary-soft: #e4ebe6;
  --paper: #f7f5f1;
  --paper-2: #efece6;
  --ink: #333;
  --muted: #888;
  --line: #ddd;
  --danger: #dc2626;
  --cancel: #6c757d;
  --font-md: 14px;
  --font: "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --display: "Cormorant Garamond", "Times New Roman", serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: #e7e3db;
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--font-md);
  line-height: 1.55;
}

button {
  height: 30px;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}

input,
textarea {
  font-family: inherit;
  font-size: var(--font-md);
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 3px;
}

input:focus,
textarea:focus,
input:focus-visible,
textarea:focus-visible {
  outline: none !important;
  box-shadow: none !important;
  border-color: var(--line);
}

textarea {
  resize: none !important;
}

.app {
  max-width: 440px;
  min-height: 100vh;
  margin: 0 auto;
  background: var(--paper);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}

.app:has(.chat-view:not([hidden])) {
  height: 100vh;
  overflow: hidden;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--primary-color);
}

.brand-mark {
  display: flex;
}

.wordmark {
  display: block;
  font-family: var(--display);
  font-weight: 600;
  font-size: 20px;
  letter-spacing: 0.04em;
  line-height: 1;
}

.tag {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 400;
  letter-spacing: 0.02em;
}

.view {
  padding: 18px 16px 24px;
}

.chat-view {
  flex: 1;
  display: none;
  flex-direction: column;
  padding: 0;
  min-height: 0;
  overflow: hidden;
}

.chat-view:not([hidden]) {
  display: flex;
}

.title {
  margin: 0 0 10px;
  font-family: var(--display);
  font-weight: 600;
  font-size: 28px;
  line-height: 1.25;
  color: var(--primary-color);
}

.title.home {
  margin: 8px 0 22px;
  font-size: 30px;
  line-height: 1.35;
  letter-spacing: -0.02em;
}

.title.sm {
  font-size: 22px;
}

.lead,
.hint {
  margin: 0 0 16px;
  color: #555;
  font-size: 13px;
}

.manual-title {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
}

.manual {
  margin: 0 0 18px;
  padding: 0 0 0 18px;
  color: #555;
  font-size: 13px;
}

.manual li {
  margin: 0 0 8px;
}

.manual li:last-child {
  margin-bottom: 0;
}

.actions {
  display: flex;
  gap: 8px;
  margin: 4px 0 18px;
}

.home-actions {
  margin: 0;
  width: 100%;
}

.home-actions .btn {
  flex: 1 1 calc(50% - 4px);
  width: calc(50% - 4px);
  min-width: 0;
  height: 30px;
}

.btn {
  border: 1px solid transparent;
  border-radius: 3px;
  padding: 0 12px;
  height: 30px;
}

.btn.primary {
  background: var(--primary-color);
  color: #fff;
}

.btn.ghost {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

.btn.send {
  flex: 0 0 auto;
  min-width: 64px;
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.text-btn {
  height: auto;
  border: none;
  background: none;
  color: var(--primary-color);
  padding: 0;
  font-size: 12px;
}

.steps {
  margin: 0;
  padding: 0 0 0 18px;
  color: #555;
  font-size: 13px;
}

.steps li {
  margin: 0 0 6px;
}

.field {
  display: block;
  margin: 0 0 12px;
}

.field > span {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  color: #555;
}

.field input {
  width: 100%;
  height: 30px;
  padding: 0 8px;
}

.seg {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.seg-btn {
  height: auto;
  border: 1px solid var(--line);
  background: #fff;
  color: #555;
  border-radius: 3px;
  padding: 6px 10px;
  font-size: 12px;
}

.seg-btn.is-on {
  background: var(--primary-soft);
  border-color: var(--primary-color);
  color: var(--primary-color);
}

.chat-meta {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}

.room-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.room-code {
  font-family: var(--display);
  font-size: 22px;
  letter-spacing: 0.18em;
  color: var(--primary-color);
  font-weight: 600;
}

.meta-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.presence {
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 3px 6px;
  height: auto;
  white-space: nowrap;
}

.presence.is-on {
  color: var(--primary-color);
  border-color: var(--primary-color);
}

.wait-note {
  margin: 0;
  padding: 8px 16px;
  font-size: 12px;
  color: #888;
  background: var(--paper-2);
  border-bottom: 1px solid var(--line);
}

.thread-shell {
  position: relative;
  flex: 1;
  min-height: 0;
}

.thread {
  height: 100%;
  overflow-y: auto;
  padding: 12px 16px 8px;
}

.thread-empty {
  margin: 0;
  font-size: 13px;
  color: #888;
}

.msg {
  max-width: 86%;
  margin: 0 0 12px;
}

.msg.mine {
  margin-left: auto;
}

.msg.coach {
  max-width: 100%;
  margin: 4px 0 14px;
}

.coach-label {
  margin: 0 0 4px;
  font-size: 11px;
  color: var(--muted);
}

.msg.coach .bubble {
  background: var(--paper-2);
  border-style: dashed;
  color: #555;
  font-size: 13px;
}

.bubble {
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 8px 10px;
  background: #fff;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.mine .bubble {
  background: var(--primary-soft);
  border-color: #d5ddd8;
}

.msg-time {
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
}

.msg.mine .msg-time {
  text-align: right;
}

.mediated-toggle {
  display: block;
  margin-top: 6px;
  height: auto;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 11px;
  padding: 0;
}

.mediated-view {
  margin-top: 6px;
  padding: 8px 10px;
  border: 1px dashed var(--line);
  border-radius: 3px;
  background: #fff;
  color: #555;
  font-size: 13px;
  white-space: pre-wrap;
}

.msg.pending .bubble {
  opacity: 0.7;
}

.msg.pouch .bubble {
  border-style: dashed;
}

.pouch-label {
  margin: 0 0 4px;
  font-size: 11px;
  color: var(--muted);
}

.typing {
  margin: 0;
  padding: 0 16px 6px;
  font-size: 12px;
  color: var(--muted);
}

.turn-wait {
  margin: 0;
  padding: 4px 16px 8px;
  font-size: 13px;
  color: var(--primary-color);
}

.pouch-counts {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin: 0;
  padding: 0 16px 6px;
}

.pouch-count {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.pouch-count.is-peer {
  text-align: left;
}

.pouch-count.is-mine {
  text-align: right;
}

.pouch-count.is-on {
  color: var(--primary-color);
  font-weight: 600;
}

.pouch-cancel {
  display: block;
  margin-top: 6px;
  height: auto;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 11px;
  padding: 0;
}

.pouch-cancel:hover {
  color: var(--danger);
}

.composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px 16px 16px;
  border-top: 1px solid var(--line);
  background: var(--paper);
}

.composer.is-locked {
  opacity: 0.55;
}

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

.composer textarea {
  flex: 1;
  min-height: 30px;
  max-height: 120px;
  padding: 5px 8px;
  overflow-y: hidden;
  line-height: 1.4;
}

.composer textarea:disabled {
  background: var(--paper-2);
  color: #777;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 10040;
  max-width: 90%;
  background: var(--primary-color);
  color: #fff;
  border-radius: 3px;
  padding: 8px 12px;
  font-size: 13px;
}

.toast.error {
  background: #5c3333;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 10020;
  background: rgba(30, 32, 31, 0.35);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 12vh 16px 16px;
}

.confirm-modal {
  width: 100%;
  max-width: 360px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 16px;
}

.confirm-modal h3 {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
}

.confirm-modal p {
  margin: 0 0 16px;
  color: #555;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
}

.confirm-status {
  color: #888;
}

.confirm-modal.is-checking #confirmMessage,
.confirm-modal.is-checking #confirmOk {
  display: none;
}

.confirm-modal.is-checking .confirm-status {
  display: block;
}

.check-dots::after {
  content: "";
  animation: check-dots 1.2s steps(4, end) infinite;
}

@keyframes check-dots {
  0% {
    content: "";
  }
  25% {
    content: ".";
  }
  50% {
    content: "..";
  }
  75% {
    content: "...";
  }
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal-actions .btn.ghost {
  color: var(--cancel);
}

@media (max-width: 480px) {
  .app {
    border-left: none;
    border-right: none;
  }
}
