/* 글쓰기 공유 — 공통 스타일. 디자인 시스템: Primary #2563eb / Green #16a34a / Gold #f59e0b. */

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  --green: #16a34a;
  --green-soft: #ecfdf5;
  --gold: #f59e0b;
  --text: #1e293b;
  --muted: #64748b;
  --hairline: #e2e8f0;
  --bg: #f8fafc;
  --card: #ffffff;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-pill: 999px;
  --shadow: 0 4px 20px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.14);
  --font: "Pretendard Variable", Pretendard, -apple-system, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.container { max-width: 1180px; margin: 0 auto; padding: 0 1.25rem; }

/* ───── 헤더 ───── */
.util-header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--hairline);
}
.util-header-inner {
  display: flex; align-items: center; gap: 0.75rem;
  height: 58px;
}
.util-header .back-link, .util-header .home-link {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: var(--radius-pill);
  color: var(--muted); text-decoration: none; border: 1px solid var(--hairline);
  background: #fff; transition: all .15s;
}
.util-header .back-link:hover, .util-header .home-link:hover {
  color: var(--primary); border-color: var(--primary); background: var(--primary-soft);
}
.util-title { flex: 1; margin: 0; font-size: 1.15rem; font-weight: 800; }
.header-spacer { flex: 1; }

/* ───── 버튼 ───── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  border: none; cursor: pointer; font-family: inherit; font-weight: 700;
  border-radius: var(--radius-pill); padding: 0.7rem 1.4rem; font-size: 1rem;
  transition: transform .08s, box-shadow .15s, background .15s; text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 4px 14px rgba(37, 99, 235, .3); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-green { background: var(--green); color: #fff; box-shadow: 0 4px 14px rgba(22, 163, 74, .3); }
.btn-green:hover { filter: brightness(.95); }
.btn-ghost { background: #fff; color: var(--text); border: 1px solid var(--hairline); }
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }
.btn-danger { background: #fff; color: #dc2626; border: 1px solid #fecaca; }
.btn-danger:hover { background: #fef2f2; }
.btn-lg { padding: 0.95rem 2rem; font-size: 1.1rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ───── 역할 선택 (index) ───── */
.role-wrap { max-width: 760px; margin: 0 auto; padding: 3rem 1.25rem; text-align: center; }
.role-wrap h2 { font-size: 1.9rem; margin: 0 0 .5rem; }
.role-wrap .lead { color: var(--muted); font-size: 1.05rem; margin: 0 0 2.5rem; line-height: 1.6; }
.role-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
@media (max-width: 640px) { .role-cards { grid-template-columns: 1fr; } }
.role-card {
  display: block; text-decoration: none; color: inherit; background: var(--card);
  border: 1px solid var(--hairline); border-radius: var(--radius); padding: 2rem 1.5rem;
  box-shadow: var(--shadow); transition: transform .15s, box-shadow .15s, border-color .15s;
}
.role-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: var(--primary); }
.role-card .emoji { font-size: 2.6rem; display: block; margin-bottom: .75rem; }
.role-card h3 { margin: 0 0 .4rem; font-size: 1.3rem; }
.role-card p { margin: 0; color: var(--muted); font-size: .95rem; line-height: 1.5; }

/* ───── 카드/패널 공통 ───── */
.panel { background: var(--card); border: 1px solid var(--hairline); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ───── 입력 ───── */
.field { display: block; text-align: left; margin-bottom: 1rem; }
.field label { display: block; font-weight: 700; margin-bottom: .4rem; font-size: .95rem; }
.input {
  width: 100%; font-family: inherit; font-size: 1rem; padding: .75rem .9rem;
  border: 1.5px solid var(--hairline); border-radius: var(--radius-sm); background: #fff; color: var(--text);
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input-code {
  text-align: center; letter-spacing: .4em; font-weight: 800; font-size: 1.6rem;
  text-transform: uppercase;
}

/* ───── 학생: 입장 화면 ───── */
.join-wrap { max-width: 420px; margin: 0 auto; padding: 3rem 1.25rem; }
.join-wrap h2 { text-align: center; font-size: 1.6rem; margin: 0 0 .35rem; }
.join-wrap .sub { text-align: center; color: var(--muted); margin: 0 0 2rem; }
.join-topic { background: var(--primary-soft); color: var(--primary-dark); border-radius: var(--radius-sm);
  padding: .75rem 1rem; margin-bottom: 1.25rem; font-weight: 600; text-align: center; }

/* ───── 학생: 에디터 ───── */
.editor-main { max-width: 900px; margin: 0 auto; padding: 1rem 1.25rem 6rem; }
.topic-banner {
  background: linear-gradient(135deg, var(--primary-soft), #fff);
  border: 1px solid #dbeafe; border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm); padding: .8rem 1.1rem; margin-bottom: 1rem;
}
.topic-banner .label { font-size: .78rem; font-weight: 800; color: var(--primary); letter-spacing: .04em; }
.topic-banner .text { margin-top: .15rem; font-size: 1.05rem; font-weight: 600; }

.toolbar {
  position: sticky; top: 58px; z-index: 30;
  display: flex; flex-wrap: wrap; align-items: center; gap: .35rem;
  background: #fff; border: 1px solid var(--hairline); border-radius: var(--radius-sm);
  padding: .5rem; margin-bottom: .75rem; box-shadow: var(--shadow);
}
.tb-group { display: flex; gap: .25rem; align-items: center; }
.tb-divider { width: 1px; align-self: stretch; background: var(--hairline); margin: .15rem .3rem; }
.tb-btn {
  min-width: 38px; height: 38px; padding: 0 .55rem; border: 1px solid transparent; background: transparent;
  border-radius: 8px; cursor: pointer; font-size: 1rem; color: var(--text); font-family: inherit;
  display: inline-flex; align-items: center; justify-content: center;
}
.tb-btn:hover { background: var(--bg); }
.tb-btn.active { background: var(--primary-soft); color: var(--primary); border-color: #bfdbfe; }
.tb-btn b { font-size: 1.05rem; }
.tb-select {
  height: 38px; border: 1px solid var(--hairline); border-radius: 8px; background: #fff;
  font-family: inherit; font-size: .92rem; padding: 0 .5rem; color: var(--text); cursor: pointer;
}
.tb-color {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff; cursor: pointer;
  box-shadow: 0 0 0 1px var(--hairline); padding: 0;
}
.tb-color:hover { transform: scale(1.12); }
.tb-color.active { box-shadow: 0 0 0 2px var(--primary); }

.editor-area {
  min-height: 52vh; background: #fff; border: 1px solid var(--hairline); border-radius: var(--radius);
  padding: 1.5rem 1.6rem; font-size: 1.05rem; line-height: 1.8; box-shadow: var(--shadow);
  outline: none; overflow-wrap: break-word; word-break: break-word;
}
.editor-area:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.editor-area p { margin: 0 0 .6em; }
.editor-area:empty::before { content: attr(data-placeholder); color: #94a3b8; }

/* 하단 고정 바: 글자 수 + 제출 */
.submit-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: rgba(255,255,255,.95); backdrop-filter: blur(8px);
  border-top: 1px solid var(--hairline); padding: .7rem 1.25rem;
}
.submit-bar-inner { max-width: 900px; margin: 0 auto; display: flex; align-items: center; gap: 1rem; }
.char-count { color: var(--muted); font-size: .92rem; font-variant-numeric: tabular-nums; }
.char-count b { color: var(--text); font-weight: 800; }
.submit-bar .spacer { flex: 1; }
.save-state { font-size: .85rem; color: var(--green); font-weight: 600; min-width: 0; }

/* ───── 선생님: 대시보드 ───── */
.teacher-main { padding: 1.25rem 0 4rem; }
.setup-card { max-width: 460px; margin: 2.5rem auto; padding: 2rem; text-align: center; }
.setup-card h2 { margin: 0 0 .4rem; font-size: 1.5rem; }
.setup-card .sub { color: var(--muted); margin: 0 0 1.5rem; }

.code-banner {
  display: flex; flex-wrap: wrap; align-items: center; gap: 1rem 1.5rem;
  padding: 1.1rem 1.4rem; margin-bottom: 1.25rem;
}
.code-box { text-align: center; }
.code-box .label { font-size: .78rem; font-weight: 800; color: var(--muted); letter-spacing: .05em; }
.code-box .code {
  font-size: 2.6rem; font-weight: 900; letter-spacing: .15em; color: var(--primary);
  line-height: 1; font-variant-numeric: tabular-nums;
}
.code-meta { display: flex; gap: 1.5rem; flex: 1; min-width: 180px; }
.stat .num { font-size: 1.6rem; font-weight: 900; }
.stat .cap { font-size: .8rem; color: var(--muted); }
.code-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.topic-row { display: flex; gap: .5rem; align-items: center; margin-bottom: 1.25rem; }
.topic-row .input { flex: 1; }

.submissions-head { display: flex; align-items: center; justify-content: space-between; margin: 0 0 .85rem; }
.submissions-head h3 { margin: 0; font-size: 1.15rem; }
.sub-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.sub-card {
  background: var(--card); border: 1px solid var(--hairline); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; cursor: pointer; transition: transform .12s, box-shadow .15s, border-color .15s;
  display: flex; flex-direction: column;
}
.sub-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: var(--primary); }
.sub-card.flash { animation: cardFlash 1.1s ease; }
@keyframes cardFlash {
  0% { box-shadow: 0 0 0 3px var(--gold), var(--shadow); }
  100% { box-shadow: var(--shadow); }
}
.sub-card-head {
  display: flex; align-items: center; gap: .5rem; padding: .75rem .9rem; border-bottom: 1px solid var(--hairline);
}
.sub-avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-dark);
  display: grid; place-items: center; font-weight: 800; font-size: .95rem; flex: none;
}
.sub-name { font-weight: 800; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub-ver { font-size: .72rem; font-weight: 700; color: var(--gold); background: #fffbeb; border-radius: var(--radius-pill); padding: .1rem .5rem; }
.sub-preview {
  padding: .85rem .9rem; font-size: .92rem; color: #334155; line-height: 1.6; flex: 1;
  max-height: 150px; overflow: hidden; position: relative;
}
.sub-preview::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 28px; background: linear-gradient(transparent, #fff); }
.sub-foot { padding: .5rem .9rem; border-top: 1px solid var(--hairline); display: flex; justify-content: space-between; color: var(--muted); font-size: .8rem; }

.empty-state { text-align: center; color: var(--muted); padding: 3rem 1rem; }
.empty-state .big { font-size: 2.5rem; margin-bottom: .5rem; }

/* ───── 모달 (제출물 전체 보기) ───── */
.modal-back {
  position: fixed; inset: 0; z-index: 100; background: rgba(15,23,42,.55);
  display: none; align-items: center; justify-content: center; padding: 1.25rem;
}
.modal-back.open { display: flex; }
.modal {
  background: #fff; border-radius: var(--radius); width: min(720px, 100%); max-height: 86vh;
  display: flex; flex-direction: column; box-shadow: var(--shadow-lg); overflow: hidden;
}
.modal-head { display: flex; align-items: center; gap: .6rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--hairline); }
.modal-head .sub-avatar { width: 36px; height: 36px; }
.modal-head h3 { margin: 0; flex: 1; font-size: 1.2rem; }
.modal-close { border: none; background: var(--bg); width: 36px; height: 36px; border-radius: 50%; cursor: pointer; font-size: 1.1rem; color: var(--muted); }
.modal-close:hover { background: #e2e8f0; }
.modal-body { padding: 1.5rem 1.6rem; overflow-y: auto; line-height: 1.8; font-size: 1.05rem; }
.modal-body p { margin: 0 0 .6em; }
.modal-foot { padding: .75rem 1.25rem; border-top: 1px solid var(--hairline); color: var(--muted); font-size: .85rem; display: flex; justify-content: space-between; }

/* ───── 토스트 ───── */
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px);
  background: #0f172a; color: #fff; padding: .7rem 1.3rem; border-radius: var(--radius-pill);
  font-weight: 600; opacity: 0; pointer-events: none; transition: all .25s; z-index: 200; box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: #b91c1c; }

/* ───── 연결 상태 점 ───── */
.conn-dot { width: 9px; height: 9px; border-radius: 50%; background: #cbd5e1; display: inline-block; }
.conn-dot.on { background: var(--green); }
.conn-dot.off { background: #ef4444; }

.hidden { display: none !important; }
