* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic", Meiryo, sans-serif;
  background: #e8e4da;
  color: #222;
  -webkit-user-select: none; user-select: none;
  overscroll-behavior: none;
}
.hidden { display: none !important; }
.spacer { flex: 1; }
button { font-family: inherit; cursor: pointer; }

/* ===== ヘッダ（ワークシート再現） ===== */
#app-header {
  background: #fffdf7;
  border-bottom: 3px double #333;
  padding: 8px 16px;
  display: flex; align-items: center; gap: 16px;
}
.title-block { display: flex; align-items: center; gap: 14px; }
.grade-tag {
  background: #d8493f; color: #fff; font-weight: bold;
  border-radius: 8px; padding: 4px 10px; font-size: 15px;
}
.title-v {
  writing-mode: vertical-rl;
  font-size: 26px; font-weight: 900; letter-spacing: 2px;
  height: 130px;
  border-right: 2px solid #333; padding-right: 6px;
}
.subtitle { font-size: 13px; color: #444; writing-mode: vertical-rl; height: 130px; }
.header-right { margin-left: auto; display: flex; align-items: center; gap: 20px; }
#master-badge {
  font-size: 15px; font-weight: bold; color: #b02a20;
  border: 2px solid #b02a20; border-radius: 20px; padding: 4px 14px;
  background: #fff;
}
#master-badge #master-count { font-size: 20px; }
.name-box { border: 2px solid #333; border-radius: 8px; padding: 8px 12px; background: #fff; }
.name-row { display: flex; align-items: flex-end; gap: 6px; margin: 4px 0; }
.name-row .lbl { font-size: 12px; white-space: nowrap; }
.name-row .line { width: 110px; border-bottom: 1px solid #666; height: 16px; }

/* ===== ツールバー ===== */
#toolbar, #toolbar2 {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px; background: #f5f1e6; border-bottom: 1px solid #ccc;
}
.tool-btn {
  border: 2px solid #555; background: #fff; border-radius: 10px;
  padding: 8px 18px; font-size: 16px; font-weight: bold;
}
.tool-btn.active { background: #ffd34d; border-color: #c99a00; }
.tool-btn.parent { background: #dfe9ff; border-color: #5577cc; font-size: 13px; line-height: 1.2; }
.tool-btn small { font-size: 10px; color: #5577cc; }

/* ===== ワークシート本体 ===== */
#sheet {
  background: #fffdf7;
  margin: 12px auto; max-width: 1180px;
  padding: 18px 14px;
  border: 1px solid #bbb;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.sheet-row {
  display: flex; flex-direction: row-reverse; justify-content: flex-start;
  gap: 10px;
  padding: 14px 0 10px;
  border-bottom: 2px dotted #999;
}
.sheet-row:last-child { border-bottom: none; }

.q { display: flex; flex-direction: column; align-items: center; width: 68px; cursor: pointer; }
.q .num {
  width: 26px; height: 26px; border: 1.5px solid #333; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: bold; margin-bottom: 4px; background: #fff;
}
.q .qbody { display: flex; flex-direction: row; align-items: flex-start; gap: 3px; }
.q .yomi {
  writing-mode: vertical-rl; font-size: 13px; color: #333;
  letter-spacing: 1px; max-height: 150px;
}
.q .box {
  position: relative;
  width: 44px;
  border: 2px solid #333; background: #fff;
  display: flex; flex-direction: column;
}
.q .box .slot {
  flex: 1; border-bottom: 1.5px dashed #999;
}
.q .box .slot.fixed {
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; color: #333; border-bottom: 1.5px dashed #999;
  writing-mode: vertical-rl; letter-spacing: 0;
}
.q .box .slot:last-child { border-bottom: none; }
.q .suf { font-size: 15px; margin-top: 4px; font-weight: bold; }
.q .stamp {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 40px; font-weight: 900; pointer-events: none;
}
.q .stamp.ok { color: rgba(220, 40, 40, .85); }
.q .stamp.ng { color: rgba(40, 90, 200, .7); font-size: 30px; }
.q.mastered .num { background: #ffe27a; }
.q:active .box { background: #fff4d6; }

#empty-weak { text-align: center; padding: 40px; font-size: 18px; }

/* ===== モーダル共通 ===== */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 12px;
}
#pad, #order-modal, #parent-modal {
  background: #fffdf7; border-radius: 14px; border: 2px solid #333;
  padding: 14px; display: flex; flex-direction: column;
  max-height: 96vh;
}
#pad { width: min(96vw, 760px); }
#order-modal, #parent-modal { width: min(96vw, 860px); overflow-y: auto; }

#pad-head, #order-head, #parent-head {
  display: flex; align-items: center; gap: 14px; margin-bottom: 10px;
  font-size: 18px; font-weight: bold;
}
#pad-num {
  width: 34px; height: 34px; border: 2px solid #333; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 17px;
}
#pad-yomi { font-size: 30px; letter-spacing: 4px; }

#pad-cells { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.cell { position: relative; }
.cell canvas {
  display: block; background: #fff; border: 2.5px solid #333; border-radius: 6px;
  touch-action: none;
}
.cell.active canvas { border-color: #e33; box-shadow: 0 0 0 3px rgba(230,50,50,.25); }
.cell .guide {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center;
  font-size: 150px; color: #ddd; pointer-events: none;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
}
.cell.show-guide .guide { display: flex; }
.cell .cross {
  position: absolute; inset: 0; pointer-events: none; opacity: .35;
}
.cell .mark {
  position: absolute; top: -14px; right: -14px;
  width: 44px; height: 44px; border-radius: 50%;
  display: none; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 900; background: #fffdf7;
}
.cell .mark.ok { display: flex; color: #e02020; border: 3px solid #e02020; }
.cell .mark.ng { display: flex; color: #2050c0; border: 3px solid #2050c0; }
.cell .mark.hira { display: flex; color: #2a9d3f; border: 3px solid #2a9d3f; }
.cell .mark.empty { display: flex; color: #999; border: 3px dashed #999; font-size: 14px; }
.cell .fixed-char {
  width: 190px; height: 190px; display: flex; align-items: center; justify-content: center;
  font-size: 120px; color: #888; border: 2.5px dashed #aaa; border-radius: 6px; background: #f7f5ee;
}
.cell .hira-badge {
  position: absolute; top: -12px; left: -12px; z-index: 2;
  background: #2a9d3f; color: #fff; font-size: 12px; font-weight: bold;
  border-radius: 12px; padding: 3px 8px;
}
.cell.hira-cell canvas { border-style: dashed; border-color: #666; }
.cell .selfcheck {
  display: none; margin-top: 6px; text-align: center; gap: 8px;
}
.cell .selfcheck.on { display: flex; justify-content: center; }
.selfcheck button {
  width: 52px; height: 40px; font-size: 20px; font-weight: 900;
  border-radius: 8px; border: 2px solid #666; background: #fff;
}
.selfcheck .so { color: #e02020; }
.selfcheck .sh { color: #2a9d3f; }
.selfcheck .sx { color: #2050c0; }
.cell .ans-label { text-align: center; font-size: 22px; font-weight: bold; color: #b02a20; min-height: 28px; }

#pad-tools { display: flex; gap: 10px; margin-top: 14px; align-items: center; flex-wrap: wrap; }
.pad-btn {
  border: 2px solid #555; background: #fff; border-radius: 10px;
  padding: 10px 16px; font-size: 16px; font-weight: bold;
}
.pad-btn.grade { background: #ff5a4e; border-color: #b02a20; color: #fff; font-size: 20px; padding: 10px 30px; }
.pad-btn:disabled { opacity: .4; }
#pad-msg { min-height: 34px; text-align: center; font-size: 18px; font-weight: bold; margin-top: 8px; }
#pad-msg.good { color: #d03030; }
#pad-msg.bad { color: #2050c0; }
#pad-msg .big { font-size: 30px; }

/* ===== 書き順 ===== */
#order-body { display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; }
.order-item { text-align: center; border: 1px solid #ccc; border-radius: 10px; padding: 10px; background: #fff; }
.order-item svg { background: #fff; border: 1px solid #999; }
.order-item .oc { font-size: 26px; font-weight: bold; margin-top: 6px; }
.order-item .cnt { font-size: 13px; color: #666; }
.order-item button { margin-top: 6px; font-size: 13px; padding: 4px 10px; border-radius: 6px; border: 1px solid #888; background: #f4f4f4; }

/* ===== 保護者ダッシュボード ===== */
#parent-body { overflow-y: auto; font-size: 14px; }
.p-section { margin-bottom: 20px; border: 1px solid #ccc; border-radius: 10px; padding: 12px; background: #fff; }
.p-section h3 { margin: 0 0 10px; font-size: 16px; }
.p-cards { display: flex; gap: 12px; flex-wrap: wrap; }
.p-card { border: 1px solid #bbb; border-radius: 10px; padding: 10px 16px; text-align: center; min-width: 110px; }
.p-card .v { font-size: 26px; font-weight: 900; }
.p-card .k { font-size: 12px; color: #555; }
table.p-table { border-collapse: collapse; width: 100%; }
.p-table th, .p-table td { border: 1px solid #ccc; padding: 5px 8px; text-align: center; font-size: 13px; }
.p-table th { background: #f0ead8; }
.weak-chip {
  display: inline-block; margin: 4px; padding: 6px 12px;
  border: 2px solid #d06060; border-radius: 18px; background: #fff;
  font-size: 22px; font-weight: bold;
}
.weak-chip small { font-size: 11px; color: #a33; margin-left: 4px; }
.danger-btn { border: 2px solid #a33; color: #a33; background: #fff; border-radius: 8px; padding: 8px 14px; font-weight: bold; }

/* ===== テスト選択 ===== */
#picker { max-width: 900px; margin: 24px auto; padding: 0 16px; }
#picker h2 { font-size: 20px; }
.ws-card {
  display: flex; align-items: center; gap: 16px;
  background: #fffdf7; border: 2px solid #333; border-radius: 12px;
  padding: 14px 18px; margin-bottom: 12px; cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,.12);
}
.ws-card:active { background: #fff4d6; }
.ws-card .ws-grade { background: #d8493f; color: #fff; border-radius: 8px; padding: 4px 10px; font-weight: bold; font-size: 13px; white-space: nowrap; }
.ws-card .ws-title { font-size: 22px; font-weight: 900; }
.ws-card .ws-info { font-size: 13px; color: #555; }
.ws-card .ws-prog { margin-left: auto; text-align: right; font-weight: bold; color: #b02a20; }
.ws-card .del { margin-left: 8px; border: 1px solid #a33; color: #a33; background: #fff; border-radius: 6px; padding: 4px 8px; }

/* ===== テスト追加フォーム ===== */
.add-form textarea {
  width: 100%; height: 140px; font-size: 15px; padding: 8px;
  border: 1px solid #999; border-radius: 8px;
  -webkit-user-select: text; user-select: text;
}
.add-form input {
  font-size: 15px; padding: 6px 8px; border: 1px solid #999; border-radius: 8px;
  -webkit-user-select: text; user-select: text;
}
.add-form .row { display: flex; gap: 10px; margin-bottom: 8px; align-items: center; flex-wrap: wrap; }
.back-btn { border: 2px solid #555; background: #fff; border-radius: 10px; padding: 8px 16px; font-size: 15px; font-weight: bold; }
