/* 新しい都道府県フォーム 共通スタイル(styles.css)
   トークンと部品は CardMaker の base.css / fields.css を踏襲。
   管理画面(admin/)もこのファイルを読み込んだ上で admin.css を重ねる。 */

:root {
  --accent: #e0392f;
  --accent-2: #f0742a;
  --accent-soft: #fdeeec;
  --accent-grad: linear-gradient(135deg, #e0392f, #f0742a);
  --ink: #1e2430;
  --ink-soft: #6b7280;
  --panel-bg: rgba(255, 255, 255, 0.88);
  --border: #e3e6ec;
  --danger: #c92b22;
  --danger-soft: #fdecea;
  --ok: #1f9d55;
  --ok-soft: #e6f6ec;
  --shadow-panel: 0 24px 80px rgba(30, 36, 48, 0.08);
  --radius-panel: 22px;

  font-family: system-ui, -apple-system, "Hiragino Sans",
    "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 0% 0%, rgba(224, 57, 47, 0.1), transparent 36%),
    radial-gradient(circle at 100% 6%, rgba(240, 116, 42, 0.07), transparent 32%),
    linear-gradient(180deg, #fbfbfd 0%, #f0f1f5 100%);
  line-height: 1.5;
  color-scheme: light;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  margin: 0;
  min-width: 320px;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input,
textarea {
  -webkit-user-select: text;
  user-select: text;
}

/* ---- ページ骨格 ---- */

.page-shell {
  /* プレビューの高さ(スマホの縦積みで使う)。
     .panel-resizer のドラッグで 30dvh 〜「フォームの最初の入力が 1 行見える上限」に変わる
     (上限は app.js が .workspace と .controls-footer の実測から決める) */
  --panel-h: 46dvh;
  height: 100dvh;
  min-height: 100dvh;
  padding: 14px 14px calc(14px + env(safe-area-inset-bottom, 0px));
  overflow: hidden;
}

.app-frame {
  max-width: 1240px;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.workspace {
  --workspace-gap: 12px;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  gap: var(--workspace-gap);
  overflow: hidden;
}

/* ---- プレビュー(キャンバス) ---- */

.preview-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  min-height: 0;
  gap: 8px;
  padding: 14px;
  border-radius: var(--radius-panel);
  background: var(--panel-bg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-panel);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.canvas-wrap {
  position: relative;
  display: flex;
  flex: 1 1 0px;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.draw-canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: #ffffff;
  box-shadow: 0 18px 50px rgba(30, 36, 48, 0.12);
  touch-action: none;
  cursor: crosshair;
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
}

.draw-canvas.is-locked {
  cursor: default;
}

.tool-row {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  /* 幅の狭い端末では横スクロールで逃がす(ボタンを縮めて文字を潰さない) */
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}

.tool-row::-webkit-scrollbar {
  display: none;
}

.tool-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #ffffff;
  color: var(--ink-soft);
  font-weight: 700;
  white-space: nowrap;
  transition: background-color 120ms ease, color 120ms ease, box-shadow 120ms ease;
}

.tool-button.is-active {
  color: var(--accent);
  border-color: rgba(224, 57, 47, 0.32);
  background: var(--accent-soft);
  box-shadow: 0 6px 16px rgba(224, 57, 47, 0.12);
  cursor: default;
}

.tool-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.tool-row > * {
  flex: 0 0 auto;
}

/* ツールは「形」と「中の落書き」の 2 グループに分ける */
.tool-group {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 8px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.7);
}

.tool-group-label {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--ink-soft);
  white-space: nowrap;
}

.tool-row .tool-clear {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 14px;
}

.tool-row .tool-clear {
  margin-left: auto;
}

/* パネル下端のつまみ。ドラッグでプレビューの高さを変える(縦積みのときだけ出す) */
.panel-resizer {
  position: relative;
  display: none;
  flex: 0 0 auto;
  width: 96px;
  height: 14px;
  margin: 0 auto -2px;
  cursor: ns-resize;
  touch-action: none;
}

/* つまみ本体(中央の細い丸バー)。当たり判定は .panel-resizer 側なのでイベントは通す */
.panel-resizer-grip {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 4px;
  border-radius: 999px;
  background: rgba(30, 36, 48, 0.18);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.panel-resizer:hover .panel-resizer-grip,
.panel-resizer.is-dragging .panel-resizer-grip {
  background: var(--accent);
}

.preview-note {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 10px;
  min-height: 24px;
  margin: 0;
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--ink-soft);
  line-height: 1.4;
}

/* 判定文言は折り返しを許可し、最大 2 行に制限する(スマホ幅で「…」に切れないように) */
.preview-note-text {
  flex: 1 1 auto;
  min-width: 0;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.preview-note.is-ok {
  color: var(--ok);
}

.preview-note.is-ng {
  color: var(--danger);
}

/* 大きさメーター */
.size-meter {
  --fill: 0%;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--ink-soft);
  white-space: nowrap;
}

.size-meter-bar {
  position: relative;
  display: inline-block;
  width: 72px;
  height: 8px;
  border-radius: 999px;
  background: rgba(30, 36, 48, 0.08);
  overflow: hidden;
}

.size-meter-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--fill);
  border-radius: 999px;
  background: var(--ink-soft);
  transition: width 160ms ease;
}

.preview-note.is-ok .size-meter-fill {
  background: var(--ok);
}

.preview-note.is-ng .size-meter-fill {
  background: var(--danger);
}

/* ---- コントロール列(入力) ---- */

.controls {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  gap: 10px;
  padding: 14px;
  border-radius: var(--radius-panel);
  background: var(--panel-bg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-panel);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  overflow: hidden;
}

.controls-scroll {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  gap: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding-right: 6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(224, 57, 47, 0.55) rgba(30, 36, 48, 0.06);
}

.controls-scroll::-webkit-scrollbar {
  width: 10px;
}

.controls-scroll::-webkit-scrollbar-track {
  border-radius: 999px;
  background: rgba(30, 36, 48, 0.05);
}

.controls-scroll::-webkit-scrollbar-thumb {
  border: 2px solid #f2f3f7;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(240, 116, 42, 0.85), rgba(224, 57, 47, 0.9));
  min-height: 40px;
}

.controls-footer {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.submit-row {
  display: flex;
  flex: 0 0 auto;
  gap: 10px;
  width: 100%;
}

.submit-row > button {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
}

.status-line {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.status-line.is-closed {
  color: var(--danger);
}

.small-link-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 18px;
}

.small-link {
  display: inline-block;
  padding: 4px 2px;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.small-link:hover {
  color: var(--accent);
}

/* あなたの投稿 見出し */
.mine-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #f8fafc;
}

.mine-title {
  flex: 1 1 auto;
  font-size: 0.92rem;
  font-weight: 800;
  color: var(--ink);
}

/* ---- バッジ ---- */

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  white-space: nowrap;
  background: rgba(30, 36, 48, 0.08);
  color: var(--ink-soft);
}

.badge-pending {
  background: #fff4e0;
  color: #b3630a;
}

.badge-adopted {
  background: var(--ok-soft);
  color: var(--ok);
}

.badge-rejected {
  background: var(--danger-soft);
  color: var(--danger);
}

/* ---- フィールド ---- */

.field-group {
  margin-top: 16px;
}

.field-group:first-child {
  margin-top: 0;
}

.field-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  font-size: 0.87rem;
  font-weight: 700;
  color: var(--ink);
}

.field-required,
.field-optional {
  flex: 0 0 auto;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.field-required {
  background: var(--accent-soft);
  color: var(--accent);
}

.field-optional {
  background: rgba(30, 36, 48, 0.07);
  color: var(--ink-soft);
}

.field-help {
  margin: 8px 0 0;
  font-size: 0.78rem;
  color: var(--ink-soft);
  line-height: 1.5;
}

.field-help-warning {
  margin: 8px 0 0;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--danger);
  line-height: 1.5;
}

.text-input {
  display: block;
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #ffffff;
  color: var(--ink);
  font-size: 16px; /* iOS の自動ズーム防止 */
  font-weight: 600;
  line-height: 1.4;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.text-input::placeholder {
  color: #a3a9b5;
  font-weight: 500;
}

.text-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.text-input[readonly],
.text-input:disabled {
  background: #f4f5f8;
  color: var(--ink-soft);
  box-shadow: none;
}

.text-input[readonly]:focus {
  border-color: var(--border);
}

.text-input.is-invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.textarea,
textarea.text-input {
  resize: vertical;
  min-height: 84px;
  line-height: 1.5;
}

/* 角度 */
.angle-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.angle-input {
  flex: 0 0 auto;
  width: 108px;
  text-align: right;
  -moz-appearance: textfield;
}

.angle-input::-webkit-outer-spin-button,
.angle-input::-webkit-inner-spin-button {
  margin: 0;
  -webkit-appearance: none;
}

.angle-unit {
  flex: 0 0 auto;
  color: var(--ink-soft);
  font-weight: 700;
}

.angle-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--accent);
}

.angle-name.is-empty {
  color: var(--ink-soft);
  font-weight: 600;
}

.angle-slider-row {
  margin-top: 8px;
}

.angle-slider {
  width: 100%;
  height: 32px;
  margin: 0;
  accent-color: var(--accent);
  touch-action: pan-x;
  cursor: pointer;
}

.angle-slider.is-empty {
  opacity: 0.55;
}

.angle-slider:disabled {
  cursor: default;
  opacity: 0.5;
}

.angle-ticks {
  display: flex;
  justify-content: space-between;
  padding: 0 6px;
  font-size: 0.78rem;
  color: var(--ink-soft);
  line-height: 1;
}






/* 編集コードで開く */
.open-code-row > .text-input {
  flex: 1 1 auto;
  min-width: 0;
}

.open-code-row > button {
  flex: 0 0 auto;
}

/* ハニーポット: 画面外に置く(display:none だと bot に見抜かれやすい) */
.hp {
  position: absolute;
  left: -9999px;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* ---- ボタン ---- */

.primary-button,
.ghost-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 16px;
  border: 0;
  border-radius: 16px;
  font-weight: 700;
  white-space: nowrap;
  transition: filter 120ms ease, transform 120ms ease, box-shadow 120ms ease;
}

.primary-button svg,
.ghost-button svg,
.danger-button svg {
  flex: 0 0 auto;
}

.primary-button:disabled,
.ghost-button:disabled,
.danger-button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.primary-button {
  color: #ffffff;
  background: var(--accent-grad);
  box-shadow: 0 12px 28px rgba(224, 57, 47, 0.28);
}

.primary-button:hover:not(:disabled) {
  filter: brightness(1.05);
}

.primary-button:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: 0 6px 16px rgba(224, 57, 47, 0.24);
}

.ghost-button {
  color: var(--ink);
  background: #ffffff;
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(30, 36, 48, 0.05);
}

.ghost-button:hover:not(:disabled) {
  border-color: #ccd2dd;
  background: #fbfbfd;
}

.danger-button {
  color: #ffffff;
  background: var(--danger);
  box-shadow: 0 10px 24px rgba(201, 43, 34, 0.24);
}

.danger-button:hover:not(:disabled) {
  filter: brightness(1.06);
}

.button-row {
  display: flex;
  gap: 10px;
}

.button-row + .button-row {
  margin-top: 10px;
}

.button-row > button {
  flex: 1 1 auto;
  min-width: 0;
}

/* ---- モーダル ---- */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(30, 36, 48, 0.52);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal {
  width: min(100%, 480px);
  max-height: min(92dvh, 860px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 26px;
  border-radius: 24px;
  background: var(--panel-bg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 24px 80px rgba(30, 36, 48, 0.24);
}

.modal:focus {
  outline: none;
}

.modal-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--ink);
}

.modal p {
  margin: 14px 0 0;
  color: var(--ink-soft);
  line-height: 1.7;
}

/* 説明モーダルの本文。段落は app.js が textContent で入れる(段落内の改行は残す) */
.intro-body p {
  white-space: pre-line;
}

.modal .field-group {
  margin-top: 16px;
}

.modal .button-row {
  margin-top: 18px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 24px;
}

.modal-actions > button {
  min-width: 110px;
}

/* 編集コード表示 */
.edit-code-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.edit-code {
  flex: 1 1 auto;
  min-width: 0;
  display: block;
  padding: 10px 12px;
  border: 1px dashed #ccd2dd;
  border-radius: 12px;
  background: #f8fafc;
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.5;
  word-break: break-all;
  -webkit-user-select: all;
  user-select: all;
  -webkit-touch-callout: default;
}

.edit-code-copy {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 12px;
}

/* ---- レスポンシブ: PC(961px 以上)は左右 2 カラム ---- */

@media (min-width: 961px) {
  .page-shell {
    padding: 20px;
  }

  .workspace {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.86fr);
    grid-template-rows: minmax(0, 1fr);
    gap: 12px;
    align-items: stretch;
  }

  .preview-panel,
  .controls {
    height: 100%;
    min-height: 0;
  }
}

/* ---- スマホ(960px 以下)は縦積み ---- */

@media (max-width: 960px) {
  /*
   * パネルの周辺高さ(padding 4+4 + border 1+1 + gap 4×3 + tool-row 42 + note 1 行 18
   * + panel-resizer 14 − margin 2)= 94px。tool-row は .tool-group の padding 3+3 と
   * border 1+1 が付くのでボタン 34 + 8 = 42。
   * キャンバスは min(100%, --panel-h - 94px) 角なので、注記が 1 行のときパネル全体が
   * ちょうど --panel-h(既定 46dvh。.panel-resizer のドラッグで 30dvh 〜 実測上限)。
   * 注記が 2 行になる / メーターが 2 行目に落ちるときはパネルがその分だけ伸び、下の .controls が縮む
   * (max-height で固定するとはみ出して枠線に文字が重なるため、上限は設けない)
   */
  .preview-panel {
    flex: 0 0 auto;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 18px;
  }

  /* キャンバスは min(100%, --panel-h - 94px) 角 */
  .canvas-wrap {
    flex: 0 0 auto;
    width: min(100%, calc(var(--panel-h) - 94px));
    height: auto;
    aspect-ratio: 1 / 1;
    margin: 0 auto;
  }

  .panel-resizer {
    display: block;
  }

  .draw-canvas {
    border-radius: 12px;
  }


  .tool-row {
    gap: 6px;
  }
  .tool-group {
    gap: 3px;
    padding: 3px 6px;
    border-radius: 13px;
  }

  .tool-group-label {
    font-size: 0.66rem;
  }


  .tool-button,
  .tool-row .tool-clear {
    min-height: 34px;
    padding: 0 10px;
    border-radius: 11px;
    font-size: 0.82rem;
  }

  /* 文言が長いときはメーターを 2 行目に落とす */
  .preview-note {
    flex-wrap: wrap;
    row-gap: 2px;
    min-height: 18px;
    font-size: 0.78rem;
  }

  .size-meter-bar {
    width: 56px;
  }

  .controls {
    flex: 1 1 auto;
    padding: 10px;
    border-radius: 18px;
  }

  .controls-scroll {
    padding-right: 2px;
  }

  .controls-footer {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .primary-button,
  .ghost-button,
  .danger-button {
    min-height: 46px;
  }

  .modal {
    padding: 18px;
    border-radius: 20px;
  }

  .modal-actions {
    flex-direction: column-reverse;
    gap: 10px;
  }

  .modal-actions > button {
    width: 100%;
    min-width: 0;
  }
}

@media (max-width: 640px) {
  .page-shell {
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px));
  }

  .workspace {
    --workspace-gap: 8px;
  }

  /*
   * 2 グループ + [消去] は 360px 幅などで入りきらない。横スクロールは手がかりが
   * 出ないので([消去]が画面外だと描き直せなくなる)、狭い端末では折り返す
   */
  .tool-row {
    flex-wrap: wrap;
    row-gap: 4px;
    overflow-x: visible;
  }
}
