:root {
  color-scheme: light;
  --bg: #f6f3ea;
  --ink: #1f2933;
  --muted: #5f6b7a;
  --panel: #ffffff;
  --line: #d8dee7;
  --guide: #c8d1dc;
  --accent: #0f766e;
  --accent-dark: #0b5f59;
  --draw: #243b53;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
}

button {
  font: inherit;
}

.app {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 20px clamp(14px, 3vw, 28px) 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

h1 {
  margin: 0 0 6px;
  font-size: clamp(1.55rem, 2.5vw, 2.3rem);
  letter-spacing: 0;
}

p {
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.95rem, 1.5vw, 1.08rem);
}

.actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.tool-button,
.difficulty-button,
.pattern-button {
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
}

.tool-button {
  min-height: 48px;
  padding: 0 18px;
  background: var(--panel);
  border-color: var(--line);
  color: var(--ink);
  font-weight: 800;
}

.tool-button.primary {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.tool-button.is-active {
  background: var(--accent);
  border-color: var(--accent-dark);
  color: #fff;
}

.controls {
  margin-bottom: 14px;
}

.control-label {
  margin-bottom: 7px;
  font-size: 0.9rem;
  font-weight: 800;
}

.difficulty-buttons {
  display: grid;
  grid-template-columns: repeat(8, minmax(72px, 1fr));
  gap: 8px;
}

.pattern-buttons {
  display: grid;
  grid-template-columns: repeat(7, minmax(76px, 1fr));
  gap: 8px;
}

.difficulty-button,
.pattern-button {
  min-height: 48px;
  background: var(--panel);
  border-color: var(--line);
  color: var(--ink);
  font-size: clamp(0.86rem, 1.2vw, 1rem);
  font-weight: 800;
}

.difficulty-button.is-active,
.pattern-button.is-active {
  background: var(--accent);
  border-color: var(--accent-dark);
  color: #fff;
}

.practice-area {
  width: 100%;
  height: min(72vh, 780px);
  min-height: 560px;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 12px 28px rgb(31 41 51 / 0.08);
}

#copyCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
}

#copyCanvas.is-eraser {
  cursor: cell;
}

@media (max-width: 840px) {
  .app {
    padding-top: 12px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .actions {
    justify-content: stretch;
  }

  .tool-button {
    flex: 1 1 120px;
  }

  .difficulty-buttons {
    grid-template-columns: repeat(4, 1fr);
  }

  .pattern-buttons {
    grid-template-columns: repeat(3, 1fr);
  }

  .practice-area {
    height: 68vh;
    min-height: 520px;
  }
}

@media print {
  body {
    background: #fff;
  }

  .topbar,
  .controls {
    display: none;
  }

  .app {
    width: 100%;
    padding: 0;
  }

  .practice-area {
    height: 98vh;
    min-height: 0;
    border: 0;
    box-shadow: none;
  }
}

/* LiNest v3: Canvasの描画色と寸法は保ち、外側の操作面のみ整える。 */
@media screen {
  body.linest-themed .app {
    min-width: 0;
    padding-block: 24px 36px;
  }

  body.linest-themed .topbar,
  body.linest-themed .controls {
    min-width: 0;
    padding: 14px;
    border: 1px solid var(--linest-border);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: var(--linest-shadow);
  }

  body.linest-themed .topbar {
    padding: 18px;
  }

  body.linest-themed :where(.tool-button, .difficulty-button, .pattern-button) {
    min-width: 0;
    border-color: var(--linest-border);
    background: #ffffff;
    color: var(--linest-heading);
  }

  body.linest-themed :where(.tool-button.is-active, .difficulty-button.is-active, .pattern-button.is-active) {
    border-color: var(--linest-green);
    background: var(--linest-green);
    color: #ffffff;
  }

  body.linest-themed .practice-area {
    border-color: var(--linest-border);
    background: #ffffff;
    box-shadow: var(--linest-shadow);
  }

  body.linest-themed :where(.topbar, .actions, .difficulty-buttons, .pattern-buttons) > * {
    min-width: 0;
  }
}

@media screen and (max-width: 420px) {
  body.linest-themed .app {
    padding-inline: 10px;
  }

  body.linest-themed :where(.topbar, .controls) {
    padding: 12px;
  }

  body.linest-themed :where(.tool-button, .difficulty-button, .pattern-button) {
    padding-inline: 8px;
    white-space: normal;
  }
}
