/*!
 * Copyright (c) 2026 Tomohiko Ariki
 * Licensed under the MIT License. See LICENSE file in the project root for details.
 */

/* ==========================================================================
   トークン
   ========================================================================== */
:root {
  --board: #2e2a22;
  --board-line: rgba(255, 255, 255, 0.04);
  --paper: #efe7d2;
  --paper-b: #e4d8bc;
  --ink: #221d17;
  --cut: #b23a2e;
  --cut-dark: #8c2c22;
  --tape: #d1a94e;
  --pencil: #7a7263;
  --shadow: rgba(20, 16, 10, 0.45);

  --font-mincho: 'Shippori Mincho', serif;
  --font-mincho-b1: 'Shippori Mincho B1', serif;
  --font-gothic: 'Zen Kaku Gothic New', sans-serif;
  --font-dot: 'DotGothic16', monospace;
}

/* ==========================================================================
   リセット・土台
   ========================================================================== */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--board);
  background-image:
    repeating-linear-gradient(0deg, var(--board-line) 0 1px, transparent 1px 32px),
    repeating-linear-gradient(90deg, var(--board-line) 0 1px, transparent 1px 32px);
  color: var(--ink);
  font-family: var(--font-gothic);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

.board {
  max-width: 46rem;
  margin: 0 auto;
  padding: clamp(1.5rem, 5vw, 3.5rem) clamp(1rem, 4vw, 2rem) 5rem;
}

h1,
h2 {
  margin: 0;
}

/* ==========================================================================
   マストヘッド(署名要素: 脅迫状風カットアップ・レタリング)
   ========================================================================== */
.masthead {
  text-align: center;
  margin-bottom: clamp(2.5rem, 6vw, 4rem);
}

.ransom-title {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.1em;
  padding: 0.6em 0 0.3em;
}

.scrap {
  display: inline-block;
  font-size: clamp(2.4rem, 9vw, 4rem);
  line-height: 1;
  color: var(--ink);
  background: var(--paper);
  padding: 0.14em 0.16em 0.1em;
  box-shadow: 0.05em 0.09em 0 rgba(20, 16, 10, 0.28);
}

.scrap.f-a {
  font-family: var(--font-mincho-b1);
  font-weight: 700;
}

.scrap.f-b {
  font-family: var(--font-gothic);
  font-weight: 900;
  background: var(--paper-b);
}

.scrap.f-c {
  font-family: var(--font-dot);
  font-weight: 400;
  background: var(--paper);
  font-size: clamp(2rem, 7.6vw, 3.4rem);
  padding-top: 0.28em;
}

.scrap:nth-child(1) {
  transform: rotate(-4deg) translateY(0.06em);
}
.scrap:nth-child(2) {
  transform: rotate(3deg) translateY(-0.08em);
}
.scrap:nth-child(3) {
  transform: rotate(-2deg) translateY(0.1em);
}
.scrap:nth-child(4) {
  transform: rotate(5deg) translateY(-0.02em);
}
.scrap:nth-child(5) {
  transform: rotate(-6deg) translateY(0.04em);
}
.scrap:nth-child(6) {
  transform: rotate(2deg) translateY(-0.1em);
}
.scrap:nth-child(7) {
  transform: rotate(-3deg) translateY(0.02em);
}
.scrap:nth-child(8) {
  transform: rotate(4deg) translateY(-0.05em);
}
.scrap:nth-child(9) {
  transform: rotate(-5deg) translateY(0.08em);
}
.scrap:nth-child(10) {
  transform: rotate(3deg) translateY(-0.03em);
}

.eyebrow {
  font-family: var(--font-dot);
  color: var(--tape);
  letter-spacing: 0.08em;
  margin: 1.2rem 0 0.4rem;
}

.lead {
  color: #cdc3ab;
  max-width: 32rem;
  margin: 0 auto;
}

/* ==========================================================================
   紙片(カード)
   ========================================================================== */
.desk-section {
  margin-bottom: 2.5rem;
}

.tab-label {
  display: inline-block;
  font-family: var(--font-gothic);
  font-weight: 700;
  font-size: 1rem;
  color: var(--board);
  background: var(--tape);
  padding: 0.3em 0.9em;
  transform: rotate(-1deg);
  margin-bottom: 1rem;
}

.tab-label .meta {
  font-weight: 400;
  font-size: 0.85em;
  margin-left: 0.4em;
}

/* 「紙片」の見た目(背景・影・切り取り線・回転)は1つのセレクタリストにまとめ、
   個別ルールとの詳細度の衝突を避ける */
.paper-card,
textarea.source-text,
.file-preview {
  --tilt: -0.6deg;
  position: relative;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-mincho);
  padding: 1.2rem 1.4rem 1.4rem;
  box-shadow: 0 0.6rem 1.2rem var(--shadow);
  transform: rotate(var(--tilt));
  clip-path: polygon(
    0% 4%,
    4% 0%,
    9% 3%,
    14% 0%,
    19% 4%,
    25% 1%,
    31% 4%,
    37% 0%,
    43% 3%,
    49% 0%,
    55% 4%,
    61% 1%,
    67% 4%,
    73% 0%,
    79% 3%,
    85% 0%,
    91% 4%,
    97% 1%,
    100% 3%,
    100% 97%,
    96% 100%,
    91% 97%,
    85% 100%,
    79% 96%,
    73% 100%,
    67% 97%,
    61% 100%,
    55% 96%,
    49% 100%,
    43% 97%,
    37% 100%,
    31% 96%,
    25% 100%,
    19% 97%,
    14% 100%,
    9% 96%,
    4% 100%,
    0% 97%
  );
}

.paper-card::before {
  content: '';
  position: absolute;
  top: -0.6rem;
  left: 1.6rem;
  width: 3.2rem;
  height: 1.1rem;
  background: rgba(209, 169, 78, 0.65);
  transform: rotate(-3deg);
}

.scrap-stack > * + * {
  margin-top: 1.6rem;
}

.scrap-stack > *:nth-child(even) {
  --tilt: 0.7deg;
}

.scrap-stack > *:nth-child(3n) {
  --tilt: -0.3deg;
}

/* テキスト入力欄(paper-cardの見た目に加え、要素固有の性質のみ指定する) */
textarea.source-text {
  display: block;
  width: 100%;
  resize: vertical;
  min-height: 8rem;
  padding-top: 1.6rem;
}

/* ファイルプレビュー(同上) */
.file-preview {
  padding-top: 1.6rem;
}

.file-preview strong {
  display: block;
  font-family: var(--font-gothic);
  font-weight: 700;
  margin-bottom: 0.4rem;
}

.file-preview pre {
  max-height: 6rem;
  overflow-y: auto;
  white-space: pre-wrap;
  margin: 0.6rem 0;
  font-family: var(--font-mincho);
  color: var(--pencil);
}

/* 生成パラメータ */
.param-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1.6rem;
}

.param-field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-family: var(--font-gothic);
  font-size: 0.9rem;
  color: var(--pencil);
}

.param-field input {
  width: 7rem;
  font-family: var(--font-dot);
  font-size: 1.1rem;
  padding: 0.4rem 0.6rem;
  background: transparent;
  color: var(--ink);
  border: none;
  border-bottom: 2px dashed var(--pencil);
}

/* ==========================================================================
   カットライン(入力と生成の境目)
   ========================================================================== */
.cut-line {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--cut);
  margin: 2.5rem 0;
}

.cut-line::before,
.cut-line::after {
  content: '';
  flex: 1;
  height: 0;
  border-top: 2px dashed rgba(178, 58, 46, 0.55);
}

.scissors {
  width: 1.4rem;
  height: 1.4rem;
  flex-shrink: 0;
}

/* ==========================================================================
   ボタン・入力コントロール
   ========================================================================== */
.input-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.9rem;
  margin-top: 1.2rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

button,
.file-btn {
  font-family: var(--font-gothic);
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  border: none;
  padding: 0.65em 1.3em;
}

.ghost-btn,
.file-btn {
  background: transparent;
  color: var(--paper);
  border: 2px solid var(--paper);
}

.ghost-btn:hover,
.file-btn:hover {
  background: rgba(239, 231, 210, 0.12);
}

.ghost-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* リセットは破壊的操作のため、他の操作ボタンより控えめな文字リンク風にする */
.reset-btn {
  background: transparent;
  border: none;
  color: var(--pencil);
  text-decoration: underline dashed;
  text-underline-offset: 0.2em;
  padding: 0.65em 0.3em;
}

.reset-btn:hover {
  color: var(--cut);
}

.file-preview button {
  background: transparent;
  color: var(--cut);
  border: 1px solid var(--cut);
  font-size: 0.8rem;
  padding: 0.3em 0.8em;
  margin: 0.3rem 0;
}

.actions {
  display: flex;
  gap: 1rem;
  margin-bottom: 2.5rem;
}

.cut-btn {
  background: var(--cut);
  color: var(--paper);
  font-size: 1.05rem;
  padding: 0.75em 2em;
  box-shadow: 0.15em 0.2em 0 var(--cut-dark);
  transition:
    transform 0.12s ease,
    box-shadow 0.12s ease;
}

.cut-btn:hover {
  transform: translate(0.05em, 0.05em);
  box-shadow: 0.08em 0.1em 0 var(--cut-dark);
}

.cut-btn:active {
  transform: translate(0.15em, 0.2em);
  box-shadow: none;
}

/* ==========================================================================
   結果表示
   ========================================================================== */
.result-paper {
  font-family: var(--font-mincho);
  font-size: 1.05rem;
  white-space: pre-wrap;
  min-height: 5rem;
  margin: 0.4rem 0 1.2rem;
}

.result-paper:empty::before {
  content: 'ここに、切り貼りされた文章があらわれます。';
  color: var(--pencil);
  font-style: italic;
}

.loading-strip {
  font-family: var(--font-dot);
  color: var(--cut);
  padding: 0.6rem 0;
  border-bottom: 2px dashed var(--cut);
  background-image: repeating-linear-gradient(
    90deg,
    var(--cut) 0 10px,
    transparent 10px 20px
  );
  background-size: 200% 2px;
  background-position: 0 100%;
  background-repeat: no-repeat;
}

.error-strip {
  font-family: var(--font-gothic);
  color: var(--cut-dark);
  background: rgba(178, 58, 46, 0.08);
  border-left: 4px solid var(--cut);
  padding: 0.6rem 0.9rem;
  margin-bottom: 1rem;
}

.error-strip::before {
  content: '✂ ';
}

/* ==========================================================================
   アクセシビリティ
   ========================================================================== */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
label.file-btn:focus-within {
  outline: 3px solid var(--tape);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: no-preference) {
  .scrap {
    animation: drop-in 0.5s cubic-bezier(0.2, 0.8, 0.3, 1) both;
  }
  .scrap:nth-child(1) {
    animation-delay: 0.02s;
  }
  .scrap:nth-child(2) {
    animation-delay: 0.08s;
  }
  .scrap:nth-child(3) {
    animation-delay: 0.14s;
  }
  .scrap:nth-child(4) {
    animation-delay: 0.2s;
  }
  .scrap:nth-child(5) {
    animation-delay: 0.26s;
  }
  .scrap:nth-child(6) {
    animation-delay: 0.32s;
  }
  .scrap:nth-child(7) {
    animation-delay: 0.38s;
  }
  .scrap:nth-child(8) {
    animation-delay: 0.44s;
  }
  .scrap:nth-child(9) {
    animation-delay: 0.5s;
  }
  .scrap:nth-child(10) {
    animation-delay: 0.56s;
  }

  @keyframes drop-in {
    from {
      opacity: 0;
      transform: translateY(-0.6em) rotate(0deg) scale(0.9);
    }
  }

  .loading-strip {
    animation: cut-along 0.9s linear infinite;
  }

  @keyframes cut-along {
    from {
      background-position: 0 100%;
    }
    to {
      background-position: -20px 100%;
    }
  }
}

/* ==========================================================================
   レスポンシブ
   ========================================================================== */
@media (max-width: 30rem) {
  .param-row {
    flex-direction: column;
    gap: 1rem;
  }

  .actions {
    flex-direction: column;
  }

  .cut-btn,
  .actions .ghost-btn {
    width: 100%;
  }
}
