@import url('https://fonts.googleapis.com/css2?family=Crimson+Pro:ital,wght@0,300;0,400;0,600;1,300;1,400&family=DM+Mono:wght@300;400&family=Noto+Sans+JP:wght@300;400;500&display=swap');

* { box-sizing: border-box; margin: 0; padding: 0; }
/* Everything below is sized in rem, so this one number sets the whole
   app's scale — tuned to feel like the ~200% browser zoom that was
   previously needed for the chat screen to read comfortably. */
html { font-size: 200%; }
html, body, #root { height: 100%; }
body { font-family: 'Crimson Pro', Georgia, serif; background: #0a0a0f; }
::selection { background: #c9a96e33; }
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2a2a3a; border-radius: 2px; }

ruby { ruby-align: center; }
rt { font-size: 0.55em; color: #c9a96e88; font-family: 'Noto Sans JP', sans-serif; }

.screen { min-height: 100vh; background: #0a0a0f; }

/* ---------- Setup screen ---------- */
.setup-screen { display: flex; align-items: center; justify-content: center; padding: 2rem; }
.setup-card { background: #111118; border: 1px solid #2a2a3a; border-radius: 2px; padding: 3rem; max-width: 33.75rem; width: 100%; position: relative; }
.setup-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px; background: linear-gradient(90deg, transparent, #c9a96e, transparent); }
.setup-title { font-size: 2rem; font-weight: 300; color: #e8e0d0; letter-spacing: 0.02em; margin-bottom: 0.3rem; display: flex; align-items: baseline; gap: 0.7rem; }
.setup-title-ja { font-family: 'Noto Sans JP', sans-serif; font-size: 1.1rem; color: #c9a96e; font-weight: 300; }
.setup-subtitle { font-size: 1rem; color: #6b6b80; font-style: italic; margin-bottom: 0.6rem; }
.backend-note { font-family: 'DM Mono', monospace; font-size: 0.6rem; color: #3a3a50; margin-bottom: 2rem; letter-spacing: 0.03em; }
.field-group { margin-bottom: 1.6rem; }
.field-label { font-family: 'DM Mono', monospace; font-size: 0.65rem; color: #c9a96e; text-transform: uppercase; letter-spacing: 0.15em; margin-bottom: 0.5rem; display: block; }
.field-select { width: 100%; background: #0d0d14; border: 1px solid #2a2a3a; color: #d0c8b8; padding: 0.7rem 1rem; font-family: 'Crimson Pro', Georgia, serif; font-size: 1rem; border-radius: 1px; outline: none; cursor: pointer; transition: border-color 0.2s; appearance: none; -webkit-appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b6b80' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 1rem center; }
.field-select:focus { border-color: #c9a96e44; }
.field-input { width: 100%; background: #0d0d14; border: 1px solid #2a2a3a; color: #d0c8b8; padding: 0.7rem 1rem; font-family: 'Noto Sans JP', sans-serif; font-size: 0.95rem; border-radius: 1px; outline: none; transition: border-color 0.2s; font-weight: 300; }
.field-input::placeholder { color: #3a3a50; }
.field-input:focus { border-color: #c9a96e44; }
.level-pills { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.level-pill { padding: 0.35rem 0.8rem; border: 1px solid #2a2a3a; background: transparent; color: #6b6b80; font-family: 'DM Mono', monospace; font-size: 0.65rem; cursor: pointer; border-radius: 1px; transition: all 0.15s; letter-spacing: 0.05em; }
.level-pill:hover { border-color: #c9a96e44; color: #c9a96e; }
.level-pill.active { background: #c9a96e14; border-color: #c9a96e; color: #c9a96e; }
.start-btn { width: 100%; background: #c9a96e; color: #0a0a0f; border: none; padding: 0.9rem; font-family: 'Crimson Pro', Georgia, serif; font-size: 1.1rem; font-weight: 600; letter-spacing: 0.05em; cursor: pointer; border-radius: 1px; margin-top: 0.5rem; transition: all 0.2s; }
.start-btn:hover { background: #d4b87a; transform: translateY(-1px); }
.start-btn:active { transform: translateY(0); }
.divider { border: none; border-top: 1px solid #1e1e2a; margin: 1.5rem 0; }
.select-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.ja-hint { font-family: 'Noto Sans JP', sans-serif; font-size: 0.78rem; color: #4a4a60; margin-top: -1rem; margin-bottom: 1.6rem; font-weight: 300; }

/* ---------- Chat screen ---------- */
.chat-screen { display: flex; flex-direction: column; font-family: 'Noto Sans JP', 'Crimson Pro', Georgia, serif; }

.app-header { background: #0d0d14; border-bottom: 1px solid #1e1e2a; padding: 0.75rem 1.5rem; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; row-gap: 0.5rem; flex-shrink: 0; position: relative; }
.app-header::after { content: ''; position: absolute; bottom: 0; left: 0; right: 0; height: 1px; background: linear-gradient(90deg, transparent, #c9a96e44, transparent); }
.header-brand { font-size: 1.1rem; font-weight: 300; color: #e8e0d0; letter-spacing: 0.08em; display: flex; align-items: baseline; gap: 0.5rem; font-family: 'Crimson Pro', serif; white-space: nowrap; }
.header-brand-ja { font-family: 'Noto Sans JP', sans-serif; font-size: 0.9rem; color: #c9a96e; font-weight: 300; }
.header-meta { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.header-badge { font-family: 'DM Mono', monospace; font-size: 0.58rem; text-transform: uppercase; letter-spacing: 0.12em; padding: 0.22rem 0.55rem; border: 1px solid #2a2a3a; color: #6b6b80; border-radius: 1px; }
.error-badge { border-color: #6a2a2a; color: #e88c8c; cursor: help; }
.reset-btn { font-family: 'DM Mono', monospace; font-size: 0.58rem; text-transform: uppercase; letter-spacing: 0.1em; color: #6b6b80; background: transparent; border: 1px solid #2a2a3a; padding: 0.22rem 0.55rem; cursor: pointer; border-radius: 1px; transition: all 0.15s; }
.reset-btn:hover { color: #c9a96e; border-color: #c9a96e44; }

.main-layout { display: flex; flex: 1; overflow: hidden; height: calc(100vh - 3.0625rem); }

.conversation-pane { flex: 1; display: flex; flex-direction: column; border-right: 1px solid #1e1e2a; min-width: 0; }
.pane-header { padding: 0.6rem 1.2rem; border-bottom: 1px solid #1a1a24; display: flex; align-items: center; gap: 0.6rem; flex-shrink: 0; background: #0c0c16; }
.pane-dot { width: 5px; height: 5px; border-radius: 50%; }
.dot-gold { background: #c9a96e; }
.dot-blue { background: #6a8ae8; }
.pane-title { font-family: 'DM Mono', monospace; font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.14em; color: #5a5a70; }
.pane-right { margin-left: auto; font-family: 'DM Mono', monospace; font-size: 0.58rem; color: #c9a96e; letter-spacing: 0.06em; }
.pane-right-blue { color: #6a8ae8; }

.messages-scroll { flex: 1; overflow-y: auto; padding: 1.4rem 1.2rem; display: flex; flex-direction: column; gap: 1.3rem; }
.msg { display: flex; flex-direction: column; max-width: 80%; animation: fadeUp 0.25s ease; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant { align-self: flex-start; align-items: flex-start; }
.msg-label { font-family: 'DM Mono', monospace; font-size: 0.52rem; text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 0.35rem; color: #3a3a50; }
.msg-bubble { padding: 0.85rem 1.05rem; border-radius: 1px; font-size: 1rem; line-height: 1.8; font-family: 'Noto Sans JP', sans-serif; font-weight: 300; }
.msg.user .msg-bubble { background: #1a1a2a; border: 1px solid #2a2a3e; color: #c0b8a8; border-bottom-right-radius: 0; }
.msg.assistant .msg-bubble { background: #131320; border: 1px solid #1e1e30; color: #e0d8c8; border-bottom-left-radius: 0; border-left: 2px solid #c9a96e44; }

.typing-indicator { display: flex; gap: 4px; padding: 0.85rem 1.05rem; background: #131320; border: 1px solid #1e1e30; border-left: 2px solid #c9a96e33; align-self: flex-start; animation: fadeUp 0.2s ease; border-radius: 1px; }
.typing-dot { width: 5px; height: 5px; background: #c9a96e55; border-radius: 50%; animation: blink 1.2s ease infinite; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
.coach-loading-dot { width: 5px; height: 5px; border-radius: 50%; background: #6a8ae8; animation: blink 1.2s ease infinite; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.2; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

.input-area { border-top: 1px solid #1a1a24; padding: 0.75rem 1rem; display: flex; gap: 0.6rem; align-items: flex-end; flex-shrink: 0; background: #0c0c16; }
.chat-input { flex: 1; background: #0d0d18; border: 1px solid #2a2a3a; color: #d0c8b8; padding: 0.65rem 0.9rem; font-family: 'Noto Sans JP', sans-serif; font-size: 0.95rem; resize: none; outline: none; border-radius: 1px; transition: border-color 0.2s; min-height: 2.625rem; max-height: 7.5rem; line-height: 1.6; font-weight: 300; }
.chat-input::placeholder { color: #3a3a50; }
.chat-input:focus { border-color: #2a2a4a; }
.send-btn { background: #c9a96e; color: #0a0a0f; border: none; padding: 0.65rem 1.1rem; font-family: 'Noto Sans JP', sans-serif; font-size: 0.82rem; cursor: pointer; border-radius: 1px; height: 2.625rem; transition: all 0.15s; flex-shrink: 0; font-weight: 400; }
.send-btn:hover:not(:disabled) { background: #d4b87a; }
.send-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.coach-pane { width: 20.625rem; flex-shrink: 0; display: flex; flex-direction: column; background: #0b0b12; }
.coach-scroll { flex: 1; overflow-y: auto; padding: 0.9rem; display: flex; flex-direction: column; gap: 0.9rem; }

.coach-card { border: 1px solid #1c1c28; border-radius: 1px; overflow: hidden; animation: fadeUp 0.3s ease; background: #0e0e1a; }
.coach-card-header { padding: 0.45rem 0.75rem; background: #111120; border-bottom: 1px solid #1c1c28; display: flex; align-items: center; gap: 0.5rem; }
.coach-idx { font-family: 'DM Mono', monospace; font-size: 0.52rem; color: #353550; letter-spacing: 0.1em; flex-shrink: 0; }
.coach-user-text { font-family: 'Noto Sans JP', sans-serif; font-weight: 300; color: #484860; font-size: 0.78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 14.375rem; }
.coach-body { padding: 0.75rem; display: flex; flex-direction: column; gap: 0.65rem; }
.coach-overall { font-size: 0.86rem; color: #a09888; line-height: 1.55; font-family: 'Crimson Pro', serif; }

.coach-issues { display: flex; flex-direction: column; gap: 0.45rem; }
.issue-item { border-radius: 1px; padding: 0.55rem 0.65rem; background: #09090f; border-left: 2px solid; }
.issue-type { font-family: 'DM Mono', monospace; font-size: 0.52rem; text-transform: uppercase; letter-spacing: 0.12em; margin-bottom: 0.3rem; }
.issue-correction { display: flex; align-items: baseline; gap: 0.45rem; flex-wrap: wrap; margin-bottom: 0.28rem; font-family: 'Noto Sans JP', sans-serif; font-weight: 300; }
.issue-original { font-size: 0.88rem; color: #585870; text-decoration: line-through; text-decoration-color: #58587055; }
.issue-arrow { color: #353550; font-size: 0.72rem; }
.issue-fixed { font-size: 0.92rem; color: #d8d0c0; }
.issue-explanation { font-size: 0.76rem; color: #5c5c78; line-height: 1.45; }

.coach-positive { background: #091209; border: 1px solid #1c2a1c; border-left: 2px solid #508a50; padding: 0.45rem 0.65rem; border-radius: 1px; font-size: 0.82rem; color: #70b070; line-height: 1.45; font-family: 'Crimson Pro', serif; }
.coach-tip { background: #090914; border: 1px solid #1c1c2e; border-left: 2px solid #50508a; padding: 0.45rem 0.65rem; border-radius: 1px; font-size: 0.76rem; color: #7070a8; line-height: 1.45; font-family: 'Crimson Pro', serif; }
.tip-label { font-family: 'DM Mono', monospace; font-size: 0.5rem; text-transform: uppercase; letter-spacing: 0.1em; color: #3c3c5c; display: block; margin-bottom: 0.22rem; }

.perfect-badge { background: #091209; border: 1px solid #1c3a1c; border-radius: 1px; padding: 0.45rem 0.75rem; font-size: 0.82rem; color: #60a860; text-align: center; font-family: 'Noto Sans JP', sans-serif; font-weight: 300; }

.coach-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; gap: 0.8rem; color: #2a2a3a; text-align: center; padding: 2rem; }
.coach-empty-kanji { font-family: 'Noto Sans JP', sans-serif; font-size: 3rem; opacity: 0.12; font-weight: 300; line-height: 1; }
.coach-empty-text { font-family: 'DM Mono', monospace; font-size: 0.58rem; text-transform: uppercase; letter-spacing: 0.14em; line-height: 2; color: #2a2a3a; }

.coach-loading { display: flex; align-items: center; gap: 0.5rem; padding: 0.75rem; color: #353550; font-family: 'DM Mono', monospace; font-size: 0.58rem; letter-spacing: 0.1em; text-transform: uppercase; }

/* Pixel thresholds below (not rem) — deliberately absolute, since the
   phone breakpoint scales html's own font-size and a rem-based media
   query would be a moving target relative to the thing it's changing. */
@media (max-width: 1600px) {
  .main-layout { flex-direction: column; height: auto; }
  .conversation-pane { border-right: none; border-bottom: 1px solid #1e1e2a; min-height: 60vh; }
  .coach-pane { width: 100%; }
}

/* ---------- Phone widths ---------- */
/* Fixed rem paddings/two-column grids sized for desktop don't fit a phone
   viewport at this app's scale — overflow here doesn't just clip, it makes
   mobile browsers widen their whole layout viewport to fit the overflowing
   content, zooming everything out and defeating the phone's real width. The
   200% desktop scale (tuned for a "chat at arm's length" reading distance)
   is also just too large on a phone held close — dial it back here so
   message bubbles read as chat-sized, not oversized.
   */
@media (max-width: 960px) {
  html { font-size: 100%; }
  .setup-screen { padding: 1rem; }
  .setup-card { padding: 1.5rem; }
  .setup-title { font-size: 1.6rem; }
  .select-row { grid-template-columns: 1fr; }
  .modal-card { padding: 1.3rem; }
  .modal-overlay { padding: 0.75rem; }
}

/* ---------- Settings modal ---------- */
.setup-header-row { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.3rem; }
.ghost-btn { background: transparent; border: 1px solid #2a2a3a; color: #8a8aa0; font-family: 'DM Mono', monospace; font-size: 0.62rem; letter-spacing: 0.08em; padding: 0.35rem 0.7rem; border-radius: 1px; cursor: pointer; transition: all 0.15s; text-transform: uppercase; }
.ghost-btn:hover { border-color: #c9a96e44; color: #c9a96e; }

.key-warning { background: #1a1208; border: 1px solid #4a3a1a; border-left: 2px solid #c9a96e; color: #c9a96e; font-size: 0.85rem; padding: 0.6rem 0.8rem; border-radius: 1px; margin-bottom: 1.5rem; font-family: 'Crimson Pro', serif; }

.modal-overlay { position: fixed; inset: 0; background: rgba(5, 5, 8, 0.75); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 1.5rem; backdrop-filter: blur(2px); }
.modal-card { background: #111118; border: 1px solid #2a2a3a; border-radius: 2px; padding: 2.2rem; max-width: 30rem; width: 100%; position: relative; max-height: 90vh; overflow-y: auto; }
.modal-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px; background: linear-gradient(90deg, transparent, #6a8ae8, transparent); }
.modal-title { font-size: 1.4rem; font-weight: 300; color: #e8e0d0; margin-bottom: 0.4rem; }
.modal-subtitle { font-size: 0.85rem; color: #6b6b80; font-style: italic; line-height: 1.5; margin-bottom: 1.8rem; }
.modal-hint { font-size: 0.78rem; color: #5a5a70; line-height: 1.5; margin: -0.6rem 0 1.4rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 0.5rem; }
.key-input-row { display: flex; gap: 0.5rem; }
.key-input-row .field-input { font-family: 'DM Mono', monospace; letter-spacing: 0.02em; }

.key-warning code { font-family: 'DM Mono', monospace; background: #2a2010; padding: 0.1rem 0.3rem; border-radius: 1px; font-size: 0.85em; }
