/* ================================================================
   デジタル水墨画 - CSS
   Uses perfect-freehand (MIT License, © Steve Ruiz)
   UI骨格：紺ヘッダー + 右下フローティングツールバー + モーダル
================================================================ */

.sumi-error {
  position: fixed;
  inset: 20px;
  background: #fff7ed;
  color: #9a3412;
  border: 2px solid #fb923c;
  border-radius: 12px;
  padding: 16px;
  z-index: 9999;
  font-weight: 700;
  font-size: 15px;
}

.sumi-app,
.sumi-app * {
  box-sizing: border-box;
}

.sumi-app {
  --sumi-navy: #1e3a5f;
  --sumi-gold: #d4af37;
  --sumi-gold-dark: #b8941f;
  position: relative;
  width: 100%;
  min-height: 400px;
  background-color: #0b1220;
  /* 修正: アプリ全体の背景に画像を追加。読み込み前/失敗時は上のbackground-colorがそのまま見える */
  background-image: url('http://ict-primaryschool-juniorhighschool.com/wp-content/uploads/2026/08/ChatGPT-Image-2026年8月5日-08_27_24.jpg');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  border-radius: 10px;
  overflow: hidden;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
}
/* 背景画像の上に薄い暗幕をかけ、ヘッダー文字やツールバーの視認性を保つ */
.sumi-app::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(11, 18, 32, .38);
  z-index: 0;
  pointer-events: none;
}

.sumi-app .hidden { display: none !important; }

/* ===== ヘッダー：タイトル / ガイド文（中央） / ステータス（右） ===== */
.sumi-header {
  height: 56px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--sumi-navy);
  color: #fff;
  box-shadow: 0 3px 12px rgba(15, 30, 58, .35);
  position: relative;
  z-index: 10;
}
.sumi-title {
  font-size: clamp(15px, 2vw, 20px);
  font-weight: 900;
  white-space: nowrap;
  flex-shrink: 0;
  letter-spacing: .02em;
}
.sumi-guide {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #dbe4f0;
  transition: color .2s;
}
.sumi-guide.good { color: #8ef0b0; }
.sumi-guide.bad  { color: #ffcda3; }
.sumi-status {
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 800;
  background: rgba(255, 255, 255, .1);
  padding: 7px 14px;
  border-radius: 999px;
  white-space: nowrap;
}
.sumi-status .sumi-sep {
  display: inline-block;
  width: 8px;
}
.sumi-status .sumi-sep::before {
  content: "・";
  color: var(--sumi-gold);
}

/* ===== メイン：16:9キャンバスを中央配置 ===== */
/* 修正: 右側だけpaddingを広く取っていたため、キャンバスが中央からズレて見えていた。
   ツールバーはキャンバスに浮かせて重ねる方式なので、左右均等paddingに変更。 */
.sumi-main {
  position: relative;
  z-index: 1;
  height: calc(100% - 56px);
  padding: 16px;
}
.sumi-stage {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.sumi-canvas-frame {
  position: absolute;
  background: #f8fafc;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
}
#sumi-main-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

/* ===== フローティングツールバー：右下・縦並び（最大5アイコン） ===== */
.sumi-toolbar {
  position: absolute;
  right: 20px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 20;
}
.sumi-tool {
  width: 54px;
  height: 54px;
  border: 1px solid #e3e8ef;
  border-radius: 50%;
  background: #fff;
  color: var(--sumi-navy);
  box-shadow: 0 5px 15px rgba(21, 34, 61, .3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform .15s;
}
.sumi-tool:hover:not(:disabled) { transform: translateY(-2px); }
.sumi-tool:active:not(:disabled) { transform: scale(.96); }
.sumi-tool-primary {
  background: var(--sumi-gold);
  color: #382f14;
  border-color: var(--sumi-gold-dark);
}
.sumi-tool:disabled {
  opacity: .4;
  cursor: not-allowed;
  transform: none;
}
.sumi-tool-icon { width: 24px; height: 24px; }
.sumi-tool-img {
  width: 24px;
  height: 24px;
  pointer-events: none;
  filter: brightness(0);
  /* ツール背景（白 or ゴールド）どちらも黒アイコンで視認性を確保 */
}
.sumi-tool::after {
  content: attr(data-tip);
  position: absolute;
  right: 64px;
  top: 50%;
  transform: translateY(-50%);
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--sumi-navy);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s;
}
.sumi-tool:hover::after,
.sumi-tool:focus-visible::after { opacity: 1; }

/* ===== モーダル（設定・確認） ===== */
.sumi-overlay {
  position: absolute;
  inset: 0;
  background: rgba(11, 18, 32, .55);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 16px;
}
.sumi-modal {
  width: min(420px, 100%);
  max-height: 90%;
  overflow-y: auto;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 20px 50px rgba(15, 30, 58, .35);
  padding: 24px 22px;
}
.sumi-modal h2 {
  margin: 0 0 14px;
  font-size: 18px;
  color: var(--sumi-navy);
}
.sumi-lead {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 700;
  color: #374151;
}

.sumi-settings-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 0;
  border-bottom: 1px solid #eef2f7;
}
.sumi-settings-row:last-of-type { border-bottom: 0; }
.sumi-settings-label {
  font-weight: 900;
  font-size: 14px;
  color: var(--sumi-navy);
}

.sumi-segmented {
  display: flex;
  background: #eef2f7;
  border-radius: 999px;
  padding: 4px;
  gap: 2px;
}
.sumi-seg-btn {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 10px 8px;
  border-radius: 999px;
  font-family: inherit;
  font-weight: 800;
  font-size: 13px;
  color: #64748b;
  cursor: pointer;
  transition: all .15s;
}
.sumi-seg-btn.on {
  background: var(--sumi-navy);
  color: #fff;
}

.sumi-modal-close {
  margin-top: 18px;
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  border: 0;
  background: var(--sumi-navy);
  color: #fff;
  font-family: inherit;
  font-weight: 900;
  font-size: 15px;
  cursor: pointer;
}

.sumi-confirm-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}
.sumi-confirm-actions button {
  flex: 1;
  padding: 12px;
  border-radius: 12px;
  font-family: inherit;
  font-weight: 900;
  font-size: 15px;
  cursor: pointer;
  border: 0;
}
.sumi-confirm-cancel { background: #eef2f7; color: #31526e; }
.sumi-confirm-ok     { background: #dc2626; color: #fff; }

/* ===== レスポンシブ ===== */
@media (max-width: 640px) {
  .sumi-header { height: 50px; padding: 0 10px; gap: 8px; }
  .sumi-title { font-size: 14px; }
  .sumi-guide { font-size: 11px; }
  .sumi-status { font-size: 11px; padding: 5px 10px; }
  .sumi-main { height: calc(100% - 50px); padding: 10px; }
  .sumi-toolbar { right: 12px; bottom: 12px; gap: 9px; }
  .sumi-tool { width: 46px; height: 46px; }
  .sumi-tool-icon, .sumi-tool-img { width: 20px; height: 20px; }
  .sumi-modal { padding: 18px 16px; }
}
