/* Shared presentation refinements. Board hit targets and functional visibility
   are deliberately left to their existing components. */
:root { --ui-control: 44px; --ui-gap: 12px; }
/* Community entry and the existing engine button share one compact row.
   The engine's data-state colours, live text and click handler stay unchanged. */
.app-site .main-shell > header .header-community-status {
  display: flex; align-items: center; flex-wrap: nowrap; gap: 4px; flex: 0 0 auto;
  min-width: 0; max-width: 100%; margin-left: auto;
}
.app-site .main-shell > header .header-community-link,
.app-site .main-shell > header .header-community-status .katago-status {
  display: inline-flex; align-items: center; justify-content: center;
  box-sizing: border-box; min-height: 28px; margin: 0; padding: 3px 8px;
  border-radius: 20px; font: inherit; font-size: .8125rem;
  font-weight: 600; line-height: 1.4; white-space: nowrap;
}
.app-site .main-shell > header .header-community-link {
  flex: 0 0 auto; border: 1px solid #8fa898;
  background: #eaf0e9; color: #294a36;
}
.app-site .main-shell > header .header-community-link:hover { background: #dce9dc; }
.app-site .main-shell > header .header-community-status .katago-status {
  display: block; flex: 0 1 auto; min-width: 0;
  overflow: hidden; text-overflow: ellipsis;
}
@media (max-width: 900px) {
  .app-site .main-shell > header .header-community-link,
  .app-site .main-shell > header .header-community-status .katago-status {
    min-height: 26px; padding: 2px 6px; font-size: .75rem;
  }
}
.main-shell, main, .workspace > *, .study-panel, .panel,
.form-grid > *, .plan-card, .research-persona, .legal-shell { min-width: 0; }
h1, h2, h3, p, label, summary, .help-text, .status,
.trial-notice, .match-system-note { overflow-wrap: anywhere; }
h1, h2, h3 { line-height: 1.4; }
.button { min-height: var(--ui-control); line-height: 1.5; white-space: normal; }
input, select, textarea { max-width: 100%; }
textarea { scroll-margin-block: 80px; }
.button:focus-visible, a:focus-visible, summary:focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid #edc786; outline-offset: 3px;
}
.section-title { flex-wrap: wrap; }
.section-title h2 { flex-shrink: 1; }
.help-text, .research-status, .match-system-note { line-height: 1.7; }
.app-site .site-beta-notice { font-size: .875rem; line-height: 1.6; }
.app-site .evaluation-values [data-score] { color: #d8e5d3; }
.app-site .player-strip small { font-size: .875rem; }

/* Keep all membership levels in normal document order, without a carousel. */
.app-site .plan-grid {
  grid-auto-flow: row; grid-auto-columns: auto;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
  overflow: visible; gap: 14px; padding-bottom: 0;
}
.app-site .plan-card { scroll-snap-align: none; grid-column: auto; }
.app-site .plan-card small { font-size: .875rem; line-height: 1.6; }

/* Research tools wrap as a group; the message history is the scroll region. */
.app-site .research-toolbar { flex-wrap: wrap; overflow: visible; gap: 8px; padding: 12px; }
.app-site .research-toolbar .research-controls {
  flex: 1 1 220px; flex-wrap: wrap; gap: 8px; min-width: 0;
}
.app-site .research-toolbar .button { min-height: 44px; padding: 9px 12px; white-space: normal; }
.app-site .research-toolbar #researchClear { padding: 9px 12px; margin-left: 0; }
.app-site .research-messages {
  height: clamp(240px, 32dvh, 420px); min-height: 240px; max-height: none;
  padding: 16px; gap: 12px; overflow-y: auto;
}
.app-site .research-panel .research-top { padding: 16px; }
.app-site .research-top .selected-teacher { margin-block: 10px; }
.app-site .research-top .selected-teacher > img { width: 48px; height: 48px; }
.app-site .research-compose { padding: 0 16px 16px; }
.app-site .research-compose textarea { min-height: 88px; }
.app-site .research-compose .help-text, .research-bubble small { font-size: .875rem; }
.app-site .research-submit-row { flex-wrap: wrap; gap: 8px; }
.app-site .research-submit-row .button { min-width: 0; flex: 1 1 100px; }
.app-site .analysis-timing-controls { flex-wrap: wrap; }
.app-site .analysis-timing-controls .analysis-wait {
  flex-wrap: wrap; gap: 6px; padding: 4px 8px; font-size: .875rem;
}
.app-site .analysis-timing-controls .analysis-wait input {
  width: 64px; min-height: 44px; padding: 8px; font-size: 1rem;
}
.app-site .analysis-timing-controls .analysis-wait .button {
  min-height: 44px; padding: 8px 12px; font-size: .875rem;
}
.app-site .analysis-timing-controls .analysis-wait small {
  display: inline; font-size: .875rem; flex: 0 0 auto; white-space: nowrap;
}
.app-site .continuous-option { min-height: 44px; }
.app-site .analysis-wait-help { margin: 0 0 4px; line-height: 1.5; }
.app-site .trial-notice { margin-block: 12px; background: #294432; color: #edf1e7; }
.app-site .trial-notice a { display: inline-block; padding-block: 8px; }

/* Saving notices stay legible, including retry / reload actions. */
.app-site .save-status { flex-wrap: wrap; gap: 8px; padding: 8px 16px; font-size: .875rem; }
.app-site .save-status > span {
  flex: 1 1 220px; min-width: 0; white-space: normal;
  overflow: visible; text-overflow: clip; overflow-wrap: anywhere;
}
.app-site .save-status .button {
  min-height: 44px; padding: 8px 12px; font-size: .875rem;
  background: #f4fff9; border-color: #6c9783; color: #153d30;
}
.app-site .brand-row #headerLogin { min-height: 44px; padding: 8px; font-size: .875rem; }
.app-site .playback button { min-width: 44px; min-height: 44px; }
.app-site .board-action-row { flex-wrap: wrap; gap: 8px; }

/* Native dialogs can scroll within the available visual viewport. */
dialog:not(.full-menu) {
  box-sizing: border-box; max-width: calc(100% - 24px);
  max-height: calc(100dvh - 24px); overflow-y: auto;
}
dialog .dialog-actions { flex-wrap: wrap; gap: 10px; }
dialog .dialog-actions .button { flex: 1 1 130px; }
dialog .close { min-width: 44px; min-height: 44px; }
.full-menu { overflow-y: auto; }
.full-menu .drawer-font-controls { flex-wrap: nowrap; gap: 5px; }
.full-menu .drawer-font-controls .font-size-options {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 2px; flex: 1; min-width: 0;
}
.full-menu .drawer-font-controls button {
  min-width: 0; min-height: 44px; padding: 4px 2px;
  font-size: 12px; white-space: nowrap; line-height: 1.4;
}

/* Newly introduced guest and commentary settings share the admin rhythm. */
#experienceSettings details {
  border: 1px solid var(--border); border-radius: 10px; margin-block: 12px;
}
#experienceSettings summary { cursor: pointer; padding: 14px 16px; line-height: 1.6; }
#experienceSettings .experience-form { gap: 16px; }
#experienceSettings .experience-form label { display: grid; gap: 8px; line-height: 1.6; }
#experienceSettings .experience-form input,
#experienceSettings .experience-form select { font: inherit; padding: 10px; border-radius: 8px; }
#classroom .class-stage-picker button:disabled {
  background: #303a35; color: #c4ccc6; border-color: #839087;
  opacity: 1; border-style: dashed; cursor: not-allowed;
}
#classroom .class-curriculum button, #classroom .class-curriculum summary { min-height: 44px; }
#classroom .class-question-actions { flex-wrap: wrap; }

/* Forms and legal tables remain contained without shrinking their text. */
.legal-header, .legal-shell .section-heading { flex-wrap: wrap; }
.legal-shell .legal-nav a { min-height: 44px; display: inline-flex; align-items: center; }
.legal-shell .legal-table-wrap table { min-width: 0; table-layout: fixed; }
.legal-shell .legal-table-wrap td:first-child { min-width: 0; }
.legal-shell .consent-details summary { min-height: 44px; line-height: 1.6; }
.legal-shell .admin-login-helper { display: inline-block; padding-block: 12px; font-size: .75rem; }

@media (min-width: 901px) {
  .app-site main { padding: 20px clamp(20px, 2vw, 36px); }
  .app-site .workspace { gap: 18px; }
  .app-site.research-mode .page-heading,
  .app-site.match-mode .page-heading,
  .app-site.screen-analysis-mode .page-heading {
    min-height: 0; padding: 16px 20px; margin-bottom: 16px;
  }
  .app-site .board-card { padding: 16px; }
  .app-site .board-wrap {
    box-sizing: border-box; width: 100%;
    max-width: min(100%, clamp(400px, calc(100dvh - 300px), 780px));
    margin-inline: auto;
  }
}
@media (max-width: 1100px) {
  #depthSettings .depth-column-head { display: none; }
  #depthSettings .depth-setting-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  #depthSettings .depth-tier { grid-column: 1 / -1; }
  #depthSettings label > span {
    position: static; width: auto; height: auto; overflow: visible;
    clip-path: none; white-space: normal;
  }
}
@media (max-width: 900px) {
  .app-site .mobile-menu-toggle { width: 44px; height: 44px; }
  .app-site .workspace, .app-site.research-mode .workspace { grid-template-columns: minmax(0, 1fr); }
  .app-site .board-wrap { max-width: 640px; margin-inline: auto; }
  .app-site .brand-row { min-height: 44px; }
}
@media (max-width: 680px) {
  .app-site main { padding-inline: 12px; }
  .app-site .board-card { margin-inline: 0; padding: 6px; }
  .app-site .board-wrap { padding: 3px; width: 100%; box-sizing: border-box; }
  .app-site .board-top { flex-wrap: wrap; gap: 8px; }
  .app-site .board-tabs { display: flex; flex-wrap: wrap; }
  .app-site .board-tabs button { min-height: 44px; padding: 8px 12px; }
  .app-site .player-strip { gap: 8px; padding: 12px 4px; }
  .app-site .player-strip strong { font-size: 1rem; }
  .app-site .player-strip small { font-size: .875rem; }
  .app-site .board-caption { flex-wrap: wrap; gap: 8px; }
  .app-site .board-action-row .button { flex: 1 1 120px; }
  .app-site.research-mode .analysis-timing-controls,
  .app-site.screen-analysis-mode .analysis-timing-controls { grid-template-columns: minmax(0, 1fr); }
  .app-site .analysis-timing-controls .continuous-option { justify-self: start; white-space: normal; }
  .app-site .research-toolbar .research-controls { flex-basis: 100%; }
  .app-site .research-toolbar .research-controls .button { flex: 1 1 100px; }
  .app-site .research-messages { height: clamp(240px, 40dvh, 360px); }
  .app-site .research-bubble.user { margin-left: 12px; }
  .app-site .research-top p { font-size: .875rem; }
  .app-site .plan-grid { grid-template-columns: minmax(0, 1fr); }
  .app-site .plan-card { padding: 18px; }
  .app-site input:not([type=checkbox]):not([type=range]),
  .app-site select, .app-site textarea { font-size: 1rem; }
  #classroom .class-stage-picker { gap: 10px; }
  #classroom .class-stage-picker .button { flex: 1 1 140px; }
  #classroom .class-question-actions .button { flex: 1 1 120px; }
  .legal-shell { padding-inline: 12px; }
  .legal-shell .legal-section { padding: 18px 14px; }
  .legal-shell .legal-table-wrap th, .legal-shell .legal-table-wrap td {
    padding: 10px 6px; font-size: .875rem; word-break: normal;
  }
}
@media (max-width: 400px) {
  #depthSettings .depth-setting-row { grid-template-columns: minmax(0, 1fr); }
  .app-site .brand-row:has(#headerLogin:not([hidden])) .brand { font-size: 1.125rem; }
  .app-site .research-panel .research-top { padding: 14px; }
}

.app-site .player-strip > div:not(.board-evaluation-center) small {
  font-size: .875rem; white-space: normal; overflow-wrap: anywhere;
}
.app-site .player-strip b { font-size: 1rem; }
.app-site .research-top .selected-teacher select,
.app-site .research-top .learner-rank-label select { min-height: 44px; }
.app-site .research-compose .research-option { min-height: 44px; padding: 8px; }
.app-site .research-submit-row .voice-button { flex: 0 0 44px; }
.app-site .screen-analysis .screen-usage-notice p { font-size: .875rem; line-height: 1.65; }
.app-site .pc-member-form { flex-wrap: wrap; }
.app-site .pc-member-form label { flex: 1 1 160px; }

/* Ledger and cost tables become labelled records on phones. Keep native
   header cells available to assistive technology and all actions in place. */
@media (max-width: 680px) {
  .cash-history thead, #aiCostPanel thead {
    position: absolute; width: 1px; height: 1px; padding: 0;
    overflow: hidden; clip-path: inset(50%); white-space: nowrap;
  }
  .cash-history table, .cash-history tbody, #aiCostPanel table, #aiCostPanel tbody {
    display: block; width: 100%; min-width: 0;
  }
  .cash-history tbody tr, #aiCostRows tr {
    display: grid; grid-template-columns: minmax(0, 1fr);
    border: 1px solid var(--border); border-radius: 8px; margin-block: 12px;
  }
  .cash-history tbody td, #aiCostRows td {
    display: grid; grid-template-columns: minmax(70px, .7fr) minmax(0, 2fr);
    gap: 10px; min-width: 0; padding: 10px; overflow-wrap: anywhere;
  }
  .cash-history tbody td::before, #aiCostRows td::before { color: #c2d1c1; font-weight: 600; }
  .cash-history td:nth-child(1)::before { content: '일시'; }
  .cash-history td:nth-child(2)::before { content: '내용'; }
  .cash-history td:nth-child(3)::before { content: '일반 캐시'; }
  .cash-history td:nth-child(4)::before { content: '보너스'; }
  .cash-history td:nth-child(5)::before { content: '사유·처리자'; }
  .cash-history td:nth-child(6)::before { content: '관리'; }
  #aiCostRows td:nth-child(1)::before { content: '구분 / 사범'; }
  #aiCostRows td:nth-child(2)::before { content: '모델'; }
  #aiCostRows td:nth-child(3)::before { content: '요청 / 완료'; }
  #aiCostRows td:nth-child(4)::before { content: '입력 / 출력 / 캐시 토큰'; }
  #aiCostRows td:nth-child(5)::before { content: '계산 비용'; }
  #aiCostRows td:nth-child(6)::before { content: '평균'; }
}

/* Analysis updates change their content, never collapse their layout slots.
   Hidden countdowns remain invisible and excluded from accessibility output. */
.app-site .board-evaluation [data-cooldown],
.app-site .board-evaluation [data-cooldown]:not([hidden]),
.app-site .board-evaluation [data-cooldown][hidden] {
  display: block !important;
  block-size: 1.5em; line-height: 1.5; white-space: nowrap;
}
.app-site .board-evaluation [data-cooldown][hidden] { visibility: hidden; }
.app-site .board-evaluation [data-visits] { min-block-size: 1.5em; line-height: 1.5; }
.app-site .board-evaluation .evaluation-track[hidden] {
  display: block !important; visibility: hidden;
}
.app-site .board-analysis-status { min-block-size: 1.65em; }
.app-site .board-analysis-status:empty { display: block; visibility: hidden; }

/* Overlay uses the board's existing space: no board shift when commentary starts. */
.app-site .board-wrap { position: relative; }
.match-commentary-notice { display: none; }
.app-site.match-mode .match-commentary-notice:not([hidden]) {
 display: flex; align-items: center; gap: 10px; position: absolute; z-index: 12;
 inset-inline: 12px; bottom: 12px; padding: 12px 14px; border: 1px solid #c8dca6;
 border-radius: 10px; background: #163c2b; color: #fff9e9;
 box-shadow: 0 3px 16px #0005; font-size: 1rem; line-height: 1.5;
 pointer-events: none; overflow-wrap: anywhere;
}
.commentary-spinner { flex: 0 0 20px; width: 20px; height: 20px;
 border: 3px solid #69836d; border-top-color: #fff9e9; border-radius: 50%;
 animation: commentary-spin 1s linear infinite; }
@keyframes commentary-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .commentary-spinner { animation: none; } }
@media (max-width: 680px) {
 .app-site.match-mode .match-commentary-notice:not([hidden]) { inset-inline: 6px; bottom: 6px; padding: 10px; gap: 8px; font-size: .9375rem; }
}

/* Match controls retain their existing handlers and use visual ordering only. */
.app-site.match-mode .board-actions{display:grid;grid-template-columns:repeat(6,minmax(0,1fr));gap:6px}
.app-site.match-mode .board-actions .board-action-row{display:contents}
.app-site.match-mode .board-actions .button{min-width:0;width:100%;min-height:48px;padding:9px 3px;font-size:.875rem;line-height:1.4;white-space:nowrap;text-align:center;justify-content:center}
.app-site.match-mode #showMoveNumbers{order:1}
.app-site.match-mode #pass{order:2}
.app-site.match-mode #matchHint{order:3}
.app-site.match-mode #matchUndo{order:4}
.app-site.match-mode #matchScore{order:5}
.app-site.match-mode #save{order:6}
body:not(.match-mode) .match-hint-button{display:none!important}
.app-site.match-mode.match-hint-visible .hotspot{display:flex!important}
.app-site.match-mode.match-hint-visible .pv-layer{display:block!important}
.app-site.match-mode.match-hint-visible .pv-note:not([hidden]){display:flex!important}
@media(max-width:680px){.app-site.match-mode .board-actions{grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}}

@media(max-width:680px){.app-site.match-mode .board-actions .board-action-row>.button{min-height:56px}}

/* Compact status bars; status text stays on one line without changing saving. */
.app-site .save-status{flex-wrap:nowrap;gap:4px;padding:2px 12px;font-size:.75rem;line-height:1.35}
.app-site .save-status>span{flex:1 1 auto;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;overflow-wrap:normal}
.app-site .save-status .button{flex-shrink:0;min-height:26px;padding:2px 6px;font-size:.75rem;line-height:1.3;white-space:nowrap}
.member-picker{display:flex;flex-wrap:wrap;gap:8px;margin-block:12px}.member-picker input{flex:1;min-width:180px}
.member-detail-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:12px;margin:12px 0}
.member-detail-grid div{min-width:0;padding:10px;border:1px solid #657957;border-radius:8px}.member-detail-grid dt{font-size:.875rem;opacity:.85}.member-detail-grid dd{margin:4px 0 0;overflow-wrap:anywhere}
.member-usage-form{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px;margin:12px 0}.member-usage-form>p,.member-usage-form>button{grid-column:1/-1}.member-usage-form label{display:grid;gap:6px}.member-usage-form input{min-width:0;width:100%}.member-usage-form .pc-notice{white-space:pre-line}
.app-site .depth-column-head,.app-site .depth-setting-row{grid-template-columns:minmax(70px,.7fr) repeat(5,minmax(90px,1fr))}
@media(max-width:900px){.app-site .depth-column-head{display:none}.app-site .depth-setting-row{grid-template-columns:repeat(2,minmax(0,1fr))}.app-site .depth-setting-row label>span{display:block}.app-site .depth-tier{grid-column:1/-1}}
@media(max-width:680px){
 .app-site .save-status{padding:2px 6px;gap:3px}.app-site .save-status .full-label{display:none}.app-site .save-status .compact-label{display:inline}
 .app-site .save-status .button{padding:2px 4px;font-size:.75rem}
 .app-site .site-beta-notice{display:block;padding:4px 8px;margin:0;font-size:.75rem;line-height:1.35;min-height:0}
 .app-site .site-beta-notice strong{font-size:inherit;line-height:inherit;white-space:nowrap}.app-site .site-beta-notice p{display:none}
 .member-detail-grid{grid-template-columns:repeat(2,minmax(0,1fr));gap:6px}.member-usage-form{grid-template-columns:1fr}
}

@media(max-width:680px){.app-site .site-beta-notice strong{margin:0}}

/* Match the existing ID selector so six desktop fields occupy one actual row. */
@media(min-width:769px){
 .app-site #depthSettings .depth-column-head,.app-site #depthSettings .depth-setting-row{display:grid;grid-template-columns:minmax(56px,.65fr) minmax(78px,1.15fr) repeat(3,minmax(62px,1fr)) minmax(78px,1.05fr);gap:8px;padding:10px 8px}
 .app-site #depthSettings .depth-column-head{font-size:.875rem;white-space:nowrap}
 .app-site #depthSettings .depth-tier{grid-column:auto;gap:0;font-size:.875rem}.app-site #depthSettings .depth-tier span{display:none}
 .app-site #depthSettings label>span{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
 .app-site #depthSettings input,.app-site #depthSettings select{min-width:0;width:100%;min-height:40px;padding:6px;font-size:.875rem;box-sizing:border-box}
}
@media(max-width:768px){
 .app-site #depthSettings .depth-column-head{display:none}.app-site #depthSettings .depth-setting-row{grid-template-columns:repeat(2,minmax(0,1fr));gap:12px;padding:12px}
 .app-site #depthSettings .depth-tier{grid-column:1/-1}.app-site #depthSettings label>span{position:static;width:auto;height:auto;clip-path:none;overflow:visible;white-space:normal}
}
.member-remaining dd{font-size:1.25rem;font-weight:700;color:#e6efce}.member-remaining>div{background:#223f31}
.member-usage-sections{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:16px}.member-usage-section{min-width:0;padding:12px;border:1px solid #657957;border-radius:10px}.member-usage-section h4{font-size:1.125rem;margin:0 0 12px}.member-usage-section .member-detail-grid{grid-template-columns:repeat(2,minmax(0,1fr));gap:6px}.member-usage-section .member-usage-form{grid-template-columns:1fr}.member-usage-section .member-usage-form small{font-size:.875rem;line-height:1.5}
@media(max-width:1000px){.member-usage-sections{grid-template-columns:1fr}}

.local-ai-preparing{position:absolute;inset:auto .5rem .5rem;z-index:8;display:flex;align-items:center;gap:.6rem;padding:.6rem .8rem;background:#19382c;color:#f4f6ee;border:1px solid #b6cc8c;border-radius:.65rem;font-size:.9rem;line-height:1.5;box-shadow:0 2px 10px #0005}.local-ai-preparing[hidden]{display:none}.local-ai-preparing progress{width:5rem;flex-shrink:0;accent-color:#d0e4a7}.local-ai-admin{display:grid;gap:.8rem}.local-ai-admin>label,.local-ai-admin fieldset{display:grid;gap:.4rem}.local-ai-admin input,.local-ai-admin select,.local-ai-admin textarea{max-width:100%;min-height:2.5rem}.local-ai-admin fieldset{min-width:0}.local-ai-admin textarea{width:100%;font-size:.85rem}@media(max-width:600px){.local-ai-preparing{font-size:.85rem;padding:.5rem;gap:.4rem}.local-ai-preparing progress{width:3rem}}

.app-site.match-mode .board-tabs,.app-site.classroom-mode .board-tabs{display:none}
.app-site .board-top{flex-wrap:wrap}.app-site .edit-toolbar button{min-height:44px;padding:8px 12px;font-size:.875rem}.app-site .business-info{width:100%;margin:0;line-height:1.7;overflow-wrap:anywhere}.app-site .site-beta-notice strong{white-space:normal}
@media(max-width:680px){.app-site .site-beta-notice strong{font-size:.6875rem}.app-site .edit-toolbar{gap:6px}.app-site .edit-toolbar label{width:100%;margin:0}}

.app-site .analysis-display-settings{padding:12px 0;display:grid;gap:8px}.app-site .analysis-display-settings input{width:5rem;min-height:44px}.app-site #pcAnalysisTag{min-height:1.5em}
