/* OLTANA Innovator - 共通CSS */

:root {
  --bg: #fafaf7;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-muted: #6b6b6b;
  --accent: #e8851e;
  --accent-light: #fff3e6;
  --accent-dark: #c66f12;
  --border: #e5e5e0;
  --green: #22863a;
  --green-light: #e6f6ea;
  --red: #cb2431;
  --red-light: #ffeef0;
  --gray: #999999;
  --radius: 10px;
  --font: "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ========== ログイン画面 ========== */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .06);
  padding: 40px 32px 32px;
  width: 100%;
  max-width: 380px;
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}
.login-logo .brand {
  font-size: 36px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 2px;
}
.login-logo .sub {
  color: var(--text-muted);
  font-size: 13px;
  letter-spacing: 1px;
  margin-top: 4px;
}

.form-row { margin-bottom: 18px; }
.form-row label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.form-row input[type="text"],
.form-row input[type="password"] {
  width: 100%;
  padding: 11px 12px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-family: var(--font);
}
.form-row input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.btn {
  display: inline-block;
  border: none;
  border-radius: 8px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font);
  transition: background .15s;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
}
.btn-primary:hover { background: var(--accent-dark); }

.alert {
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 18px;
  font-size: 14px;
}
.alert-error {
  background: var(--red-light);
  color: var(--red);
  border: 1px solid #f5c6cb;
}

.login-footer {
  margin-top: 22px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}

/* ========== ホーム画面 ========== */
.site-header {
  background: #fff;
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
.header-left { display: flex; align-items: baseline; gap: 12px; }
.header-brand {
  font-size: 20px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 1px;
}
.header-sub { color: var(--text-muted); font-size: 13px; }
.header-right { display: flex; align-items: center; gap: 16px; }
.greeting { font-size: 14px; }
.btn-logout {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
}
.btn-logout:hover { background: #f0f0eb; text-decoration: none; }

.main { max-width: 1100px; margin: 0 auto; padding: 32px 24px; }
.page-title { font-size: 22px; font-weight: 700; margin: 0 0 6px; }
.page-subtitle { color: var(--text-muted); font-size: 14px; margin: 0 0 24px; }

.empty-state {
  background: #fff;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  color: var(--text-muted);
}

/* 問題カードグリッド */
.mission-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}
@media (max-width: 900px) { .mission-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .mission-grid { grid-template-columns: 1fr; } }

.mission-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.mission-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, .06);
  border-color: var(--accent);
  text-decoration: none;
}
.card-mission-no {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 1px;
  margin-bottom: 6px;
}
.card-title {
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 12px;
  line-height: 1.4;
}
.card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: auto;
}
.level-badge {
  font-size: 12px;
  background: var(--accent-light);
  color: var(--accent-dark);
  padding: 3px 8px;
  border-radius: 4px;
  font-weight: 600;
}

/* ステータスバッジ */
.status {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.status-not-started { background: #f0f0eb; color: var(--gray); }
.status-submitted   { background: var(--accent-light); color: var(--accent-dark); }
.status-cleared     { background: var(--green-light); color: var(--green); }

/* ========== mission画面 ========== */

/* mission ヘッダー（ホームと共通の site-header に追加で表示する mission タイトル） */
.mission-header-title {
  font-size: 15px;
  color: var(--text);
  border-left: 1px solid var(--border);
  padding-left: 16px;
  margin-left: 4px;
}

/* レイアウト：左（問題情報） 320px / 中央（エディタ） 残り / 右（実行結果） 380px */
.mission-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 420px;
  gap: 14px;
  max-width: 1600px;
  margin: 0 auto;
  padding: 16px 20px;
  align-items: start;
}
@media (max-width: 1280px) {
  /* 中サイズ画面：左固定 / 右(エディタ + 実行結果が縦並び) */
  .mission-layout { grid-template-columns: 320px minmax(0, 1fr); }
  .center-panel { grid-column: 2; }
  .canvas-panel { grid-column: 2; }
}
@media (max-width: 900px) {
  .mission-layout { grid-template-columns: 1fr; }
  .center-panel, .canvas-panel { grid-column: 1; }
}

/* カード共通 */
.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 14px;
}
.card-header {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 12px;
}

/* 左パネル */
.left-panel { display: flex; flex-direction: column; }
.mission-back {
  font-size: 13px;
  margin-bottom: 10px;
}
.mission-back a { color: var(--accent); }

.mission-pill {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 999px;
  letter-spacing: 1px;
  margin-bottom: 12px;
}
.mission-title-big {
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 12px;
  line-height: 1.3;
}
.mission-desc {
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.7;
  margin: 0 0 6px;
  color: var(--text);
}
.status-row { margin-top: 14px; }

/* リファレンス：各関数を小カードで */
.ref-card {
  background: #faf9f5;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
.ref-card:last-child { margin-bottom: 0; }
.ref-func {
  font-family: "Consolas", "Menlo", monospace;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-dark);
  margin-bottom: 2px;
}
.ref-explain {
  font-size: 12px;
  color: var(--text-muted);
}

/* ヒント：折りたたみ */
.hint-toggle {
  width: 100%;
  background: var(--accent-light);
  color: var(--accent-dark);
  border: 1px solid #ffd9b3;
  padding: 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font);
  text-align: center;
  transition: background .15s;
}
.hint-toggle:hover { background: #ffe7cc; }
.hint-toggle.is-open { border-radius: 8px 8px 0 0; }
.hint-content {
  background: #fffbe6;
  border: 1px solid #ffe58f;
  border-top: none;
  border-radius: 0 0 8px 8px;
  padding: 12px 14px;
  font-size: 13px;
  white-space: pre-wrap;
  font-family: "Consolas", "Menlo", monospace;
  line-height: 1.7;
}
.hint-content[hidden] { display: none; }

/* 中央／右パネル */
.center-panel { display: flex; flex-direction: column; gap: 12px; }
.canvas-panel { display: flex; flex-direction: column; gap: 12px; }

.editor-card, .result-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: #faf9f5;
  gap: 8px;
  flex-wrap: wrap;
}
.section-header-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}
.section-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* 速度トグル */
.speed-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.speed-toggle button {
  background: #fff;
  border: none;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  font-family: var(--font);
  color: var(--text-muted);
  border-right: 1px solid var(--border);
}
.speed-toggle button:last-child { border-right: none; }
.speed-toggle button.is-active {
  background: var(--accent-light);
  color: var(--accent-dark);
  font-weight: 700;
}

/* ボタン */
.btn-mini {
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-family: var(--font);
}
.btn-mini:hover { background: #f0f0eb; }
.btn-reset {
  background: #fff;
  color: var(--red);
  border-color: #f5c6cb;
}
.btn-reset:hover { background: var(--red-light); }
.btn-run {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 700;
}
.btn-run:hover { background: var(--accent-dark); }
.btn-submit {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
  font-weight: 700;
  padding: 8px 18px;
  font-size: 14px;
}
.btn-submit:hover { background: #1a6b2c; }
.btn-submit:disabled { opacity: .6; cursor: not-allowed; }

.CodeMirror {
  height: 320px !important;
  font-family: "Consolas", "Menlo", monospace;
  font-size: 14px;
  border: none;
}

/* キャンバス枠：固定サイズ。背景画像はここに表示してSkulptに干渉されないようにする */
.canvas-wrap {
  width: 400px;
  height: 400px;
  margin: 12px auto;
  padding: 0;
  position: relative;
  background: #fff center/contain no-repeat;
  border: 1px solid #eee;
  border-radius: 6px;
  overflow: hidden;
}
#turtle-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 400px;
  height: 400px;
}
/* Skulptが挿入する canvas / svg を強制的にラッパーサイズに収める */
#turtle-canvas > canvas,
#turtle-canvas > svg {
  display: block;
  width: 400px !important;
  height: 400px !important;
}

/* エディタは大きめに（学習が進むと行数が増えるため） */
.CodeMirror { height: 520px !important; }
.card { padding: 14px 16px; margin-bottom: 10px; }
.section-header { padding: 8px 14px; }
.submit-bar { padding: 10px 14px; }

.console-area {
  background: #1e1e1e;
  color: #f5f5f5;
  font-family: "Consolas", "Menlo", monospace;
  font-size: 12px;
  padding: 8px 12px;
  min-height: 32px;
  white-space: pre-wrap;
  border-top: 1px solid #333;
}
.console-area.error { color: #ff8585; }
.console-area:empty { display: none; }

/* 提出バー（右パネル下） */
.submit-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--green);
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.15);
  font-size: 14px;
  font-weight: 600;
  z-index: 1000;
  opacity: 0;
  transition: opacity .3s;
  pointer-events: none;
}
.toast.show { opacity: 1; }
.save-indicator {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: 8px;
}

/* ========== 管理画面 ========== */
.admin-body { background: #f4f4f0; }
.admin-header { box-shadow: 0 2px 4px rgba(0,0,0,.04); }
.admin-nav {
  background: #fff;
  border-top: 1px solid var(--border);
}
.admin-nav .header-inner {
  display: flex;
  gap: 4px;
  padding: 0 24px !important;
}
.nav-link {
  display: inline-block;
  padding: 12px 18px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  border-bottom: 3px solid transparent;
  transition: color .15s, border-color .15s;
}
.nav-link:hover { color: var(--text); text-decoration: none; }
.nav-link.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.admin-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}
.admin-page-title {
  font-size: 22px;
  margin: 0 0 4px;
}
.admin-page-sub {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0 0 20px;
}

/* テーブル（生徒一覧） */
.admin-table-wrap {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
}
.admin-table th {
  background: #faf9f5;
  font-size: 13px;
  font-weight: 700;
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}
.admin-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.admin-table tbody tr { cursor: pointer; transition: background .1s; }
.admin-table tbody tr:hover { background: var(--accent-light); }
.admin-table tbody tr:hover .row-link-btn {
  background: var(--accent);
  color: #fff;
}
.row-link-btn {
  display: inline-block;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 700;
  background: #fff;
  color: var(--accent-dark);
  border: 1px solid var(--accent);
  border-radius: 999px;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.admin-table tbody tr:last-child td { border-bottom: none; }

.num-pill {
  display: inline-block;
  min-width: 28px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}
.num-cleared    { background: var(--green-light); color: var(--green); }
.num-submitted  { background: var(--accent-light); color: var(--accent-dark); }
.num-not-started{ background: #f0f0eb; color: var(--gray); }

.progress-bar {
  display: inline-block;
  width: 100px;
  height: 6px;
  background: #f0f0eb;
  border-radius: 3px;
  overflow: hidden;
  vertical-align: middle;
}
.progress-bar-fill { background: var(--green); height: 100%; }
.progress-bar-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: 6px;
  vertical-align: middle;
}

/* 提出コードカード（B / C / D 共通） */
.mission-card-admin, .feed-item {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.mission-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}
.code-view {
  background: #1e1e1e;
  color: #f5f5f5;
  font-family: "Consolas","Menlo",monospace;
  font-size: 13px;
  line-height: 1.6;
  padding: 12px 14px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 0;
  white-space: pre;
}
.mission-card-actions {
  margin-top: 10px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.btn-cleared {
  background: var(--green);
  color: #fff;
  border: none;
  padding: 8px 18px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  font-family: var(--font);
}
.btn-cleared:hover { background: #1a6b2c; }
.btn-cleared:disabled { opacity: .5; cursor: not-allowed; }

/* フィード */
.feed-meta {
  font-size: 13px;
  margin-bottom: 8px;
  color: var(--text);
}
.feed-time {
  color: var(--text-muted);
  margin-right: 8px;
  font-family: "Consolas","Menlo",monospace;
}
.feed-student {
  font-weight: 700;
  color: var(--accent-dark);
}

/* Mission別タブ */
.mission-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  margin-bottom: 16px;
}
.mission-tab {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 6px;
  text-decoration: none;
  background: #faf9f5;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
}
.mission-tab:hover { text-decoration: none; background: #f0f0eb; }
.mission-tab.is-active {
  background: var(--accent);
  color: #fff;
}

/* ========== 役割バッジ ========== */
.role-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}
.role-teacher { background: var(--accent-light); color: var(--accent-dark); }
.role-student { background: var(--green-light);  color: var(--green); }

/* ========== モーダル ========== */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 2000;
}
.modal[hidden] { display: none; }
.modal-card {
  background: #fff;
  width: 90%; max-width: 460px;
  border-radius: 12px;
  padding: 24px 28px;
  box-shadow: 0 10px 40px rgba(0,0,0,.2);
}
.modal-card h2 {
  margin-top: 0;
  font-size: 18px;
}
.modal-card .form-row { margin-bottom: 14px; }
.modal-card .form-row label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.modal-card .form-row input,
.modal-card .form-row select {
  width: 100%;
  padding: 8px 10px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font);
  background: #fff;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* ========== リファレンス ========== */
.ref-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 20px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
  align-items: start;
}
@media (max-width: 800px) {
  .ref-layout { grid-template-columns: 1fr; }
}
.ref-toc {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  position: sticky;
  top: 20px;
}
.ref-toc-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.ref-toc-link {
  display: block;
  padding: 6px 0;
  font-size: 14px;
  color: var(--text);
  border-bottom: 1px dotted var(--border);
}
.ref-toc-link:hover { color: var(--accent); text-decoration: none; }
.ref-toc-link:last-of-type { border-bottom: none; }
.ref-toc-note {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
}

.ref-main {
  background: transparent;
}
.ref-section {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 16px;
  scroll-margin-top: 16px;
}
.ref-section-title {
  margin: 0 0 4px;
  font-size: 20px;
}
.ref-section-desc {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0 0 16px;
}
.ref-item {
  background: #faf9f5;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.ref-item:last-child { margin-bottom: 0; }
.ref-item-syntax {
  display: inline-block;
  background: var(--accent-light);
  color: var(--accent-dark);
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 700;
  font-family: "Consolas","Menlo",monospace;
}
.ref-item-explain {
  margin: 8px 0 6px;
  font-size: 14px;
  line-height: 1.7;
}
.ref-item-example {
  background: #1e1e1e;
  color: #f5f5f5;
  font-family: "Consolas","Menlo",monospace;
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 6px;
  margin: 0;
  overflow-x: auto;
  white-space: pre;
}
