:root {
  --bg: #f5f0e8;
  --card: #ffffff;
  --text: #2c2c2c;
  --muted: #4f5a6b;
  --accent: #4a7c59;
  --accent-dark: #3f6c4c;
  --border: #e6e9f0;
  --shadow: 0 12px 30px rgba(16, 24, 40, 0.12);

  --radius: 16px;
  --tube-bg: #ffffff;
  --tube-stroke: #d7deea;
  --empty-layer-bg: #f3f5f8;

  --c0: #e85d5d; /* 赤 */
  --c1: #5d8fe8; /* 青 */
  --c2: #5de88f; /* 緑 */
  --c3: #e8c85d; /* 黄 */
  --c4: #a85de8; /* 紫 */
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans JP", "Hiragino Kaku Gothic ProN",
    "Yu Gothic", sans-serif;
  background: radial-gradient(900px 500px at 20% 0%, rgba(74, 124, 89, 0.12), transparent 50%), var(--bg);
  color: var(--text);
  padding: 16px;
}

.page {
  max-width: 980px;
  margin: 0 auto;
}

.screen.hidden {
  display: none;
}

.hidden {
  display: none !important;
}

.title {
  font-size: clamp(28px, 4vw, 44px);
  margin: 8px 0 8px;
  text-align: center;
  letter-spacing: 0.02em;
}

.subtitle {
  margin: 0 0 18px;
  text-align: center;
  color: var(--muted);
  font-size: clamp(15px, 2.2vw, 20px);
  line-height: 1.6;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  border: 1px solid var(--border);
}

.card-title {
  margin: 0 0 10px;
  font-size: 22px;
}

.level-select-scroll {
  max-height: min(60vh, 520px);
  overflow-y: auto;
  margin-top: 12px;
  padding-right: 4px;
  -webkit-overflow-scrolling: touch;
}

.level-zones {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.level-zone__title {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 800;
  color: var(--text-muted, #5a6b5e);
  text-align: center;
}

.level-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin-top: 12px;
}

.level-btn {
  min-width: 56px;
  min-height: 56px;
  font-size: 18px;
  position: relative;
}

.level-btn--cleared {
  border-color: var(--accent);
  background: rgba(74, 124, 89, 0.12);
}

.level-btn__check {
  display: block;
  font-size: 12px;
  color: var(--accent);
  font-weight: 900;
  line-height: 1;
}

.level-btn__num {
  display: block;
  line-height: 1.2;
}

.btn {
  font-size: 16px;
  padding: 12px 16px;
  border-radius: 12px;
  border: 0;
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
  cursor: pointer;
  min-height: 48px;
}

.btn.secondary {
  background: #f2f4f7;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary {
  background: #f2f4f7;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-question {
  padding: 12px 18px;
  background: #f2f4f7;
  color: var(--text);
  border: 1px solid var(--border);
  font-weight: 900;
  width: 56px;
}

.rule-link-row {
  margin-top: 12px;
  display: flex;
  justify-content: center;
}

.fineprint {
  margin: 12px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

/* Play screen */
.play-header {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
  margin: 10px 0 6px;
}

.play-title {
  font-weight: 900;
  font-size: 22px;
}

.play-moves {
  font-weight: 900;
  font-size: 16px;
  color: var(--muted);
}

.hintline {
  margin: 8px 0 14px;
  text-align: center;
  color: var(--muted);
  font-size: 16px;
  font-weight: 700;
}

.board {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  padding: 6px;
}

.tube {
  border-radius: 22px;
  transition: transform 120ms ease;
}

.tube--selected {
  transform: translateY(-6px);
}

.tube--invalid .tube__stack {
  animation: shake 0.35s ease;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-4px);
  }
  75% {
    transform: translateX(4px);
  }
}

.tube__stack {
  width: clamp(72px, 18vw, 86px);
  height: clamp(240px, 42vw, 320px);
  background: var(--tube-bg);
  border: 3px solid var(--tube-stroke);
  border-radius: 22px;
  overflow: hidden;
  display: flex;
  flex-direction: column-reverse;
  position: relative;
}

.tube--selected .tube__stack {
  border-color: var(--accent);
  box-shadow: 0 10px 25px rgba(74, 124, 89, 0.25);
}

.tube__btn {
  all: unset;
  display: block;
  cursor: pointer;
}

.tube__btn:focus-visible .tube__stack {
  outline: 4px solid rgba(74, 124, 89, 0.35);
  outline-offset: 2px;
}

.layer {
  flex: 1;
  position: relative;
  border-right: 0;
}

.layer--empty {
  background: var(--empty-layer-bg);
  border-top: 1px solid #eef1f7;
}

.layer__label {
  position: absolute;
  left: 3px;
  top: 3px;
  font-size: 10px;
  font-weight: 900;
  color: rgba(7, 16, 33, 0.85);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
}

/* Color layers (fill + border patterns) */
.layer--c0 {
  background: var(--c0);
  border: 2px solid var(--c0);
  border-style: solid;
}
.layer--c1 {
  background: var(--c1);
  border: 2px solid var(--c1);
  border-style: dashed;
}
.layer--c2 {
  background: var(--c2);
  border: 2px solid var(--c2);
  border-style: dotted;
}
.layer--c3 {
  background: var(--c3);
  border: 2px solid var(--c3);
  border-style: double;
}
.layer--c4 {
  background: var(--c4);
  border: 3px solid var(--c4);
  border-style: solid;
}

/* Bottom buttons */
.button-row {
  margin-top: 14px;
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Clear */
.clear-card {
  text-align: center;
  animation: fadeIn 280ms ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.clear-title {
  margin: 0 0 8px;
  font-size: 30px;
  letter-spacing: 0.06em;
}

.clear-subtitle {
  margin: 0;
  font-size: 18px;
  color: var(--muted);
  font-weight: 800;
}

.clear-moves {
  margin: 10px 0 0;
  font-size: 16px;
  color: var(--muted);
  font-weight: 700;
}

.clear-moves-note {
  margin: 6px 0 0;
  font-size: 20px;
  font-weight: 900;
  color: var(--accent);
}

/* Modal */
.modal {
  border: 0;
  border-radius: 14px;
  padding: 0;
  width: min(520px, calc(100vw - 24px));
}

.modal::backdrop {
  background: rgba(15, 23, 42, 0.55);
}

.modal-content {
  padding: 16px 16px 14px;
  background: #ffffff;
  border-radius: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.modal-title {
  margin: 0 0 8px;
  font-size: 20px;
}

.modal-subtitle {
  margin: 12px 0 6px;
  font-size: 16px;
}

.modal-list {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--text);
  font-weight: 700;
  line-height: 1.6;
}

.modal-rules {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.6;
}

.modal-actions {
  margin-top: 14px;
  display: flex;
  justify-content: center;
}

.auth-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.auth-gate.hidden {
  display: none;
}

.auth-card {
  width: min(100%, 400px);
  text-align: center;
}

.auth-title {
  margin: 0 0 8px;
  font-size: clamp(24px, 4vw, 32px);
}

.auth-lead {
  margin: 0 0 16px;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.5;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}

.auth-label {
  font-weight: 800;
  font-size: 16px;
}

.auth-input {
  width: 100%;
  font-size: 18px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 2px solid var(--border);
  min-height: 48px;
}

.auth-input:focus {
  outline: none;
  border-color: var(--accent);
}

.auth-error {
  margin: 0;
  color: #c0392b;
  font-weight: 800;
  font-size: 14px;
}

.auth-submit {
  width: 100%;
}

