:root {
  --paper: #f5f0e1;
  --paper-dark: #ebe4d0;
  --ink: #1a3a6b;
  --ink-soft: #3d5a80;
  --red: #c0392b;
  --line: #a8c4e0;
  --shadow: rgba(26, 58, 107, 0.12);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: "PingFang HK", "Noto Sans TC", "Microsoft JhengHei", "Hiragino Sans CNS", sans-serif;
  background: var(--paper);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  background-image:
    repeating-linear-gradient(
      transparent,
      transparent 27px,
      var(--line) 27px,
      var(--line) 28px
    );
  background-attachment: fixed;
}

#app {
  min-height: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 14px calc(16px + var(--safe-bottom));
  position: relative;
}

.screen { display: none; }
.screen.active { display: block; }

.notebook {
  text-align: center;
  padding: 48px 16px 32px;
}

.title {
  font-size: 2.6rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--ink);
  text-shadow: 1px 1px 0 var(--paper-dark);
  margin-bottom: 8px;
}

.title-sm {
  font-size: 1.25rem;
  letter-spacing: 0.12em;
  text-align: center;
}

.tagline {
  font-size: 0.9rem;
  color: var(--ink-soft);
  margin-bottom: 16px;
}

.howto {
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--ink-soft);
  max-width: 320px;
  margin: 0 auto 28px;
}

.btn {
  appearance: none;
  border: 2px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  padding: 12px 22px;
  border-radius: 10px;
  cursor: pointer;
  box-shadow: 2px 3px 0 var(--shadow);
  transition: transform 0.08s, box-shadow 0.08s;
}

.btn:active {
  transform: translate(1px, 2px);
  box-shadow: 1px 1px 0 var(--shadow);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--ink);
  color: var(--paper);
  font-size: 1.15rem;
  padding: 14px 36px;
  letter-spacing: 0.08em;
}

.btn-rps {
  flex: 1;
  min-width: 0;
  font-size: 1.05rem;
  padding: 16px 8px;
}

.btn-action {
  font-size: 1rem;
  padding: 14px 20px;
  min-width: 140px;
}

.disclaimer {
  margin-top: 28px;
  text-align: center;
  font-size: 0.68rem;
  color: #8a9bb0;
  letter-spacing: 0.02em;
}

.game-header {
  text-align: center;
  margin-bottom: 10px;
}

.phase-status {
  font-size: 0.9rem;
  color: var(--ink-soft);
  margin-top: 4px;
}

.boards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.side {
  background: rgba(255, 255, 255, 0.45);
  border: 1.5px dashed var(--line);
  border-radius: 12px;
  padding: 10px 12px 12px;
}

.side-label {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.phase-chip {
  font-size: 0.72rem;
  font-weight: 500;
  background: var(--paper-dark);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  color: var(--ink-soft);
}

.vs-divider {
  text-align: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--red);
  letter-spacing: 0.2em;
  opacity: 0.7;
}

.fortress {
  position: relative;
  width: 160px;
  margin: 0 auto;
  padding: 18px 14px 10px;
}

.flags {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 2px;
  min-height: 18px;
  font-size: 0.95rem;
  line-height: 1;
  z-index: 2;
}

.shields {
  position: absolute;
  inset: 8px 4px 2px;
  pointer-events: none;
  z-index: 1;
}

.shield-arc {
  position: absolute;
  inset: 0;
  border: 2px solid var(--ink);
  border-radius: 14px;
  opacity: 0.55;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border: 2px solid var(--ink);
  position: relative;
  z-index: 2;
  background: rgba(255, 252, 245, 0.9);
}

.cell {
  aspect-ratio: 1;
  border: 1px solid var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 52px;
}

.cell .glyph {
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--ink);
  line-height: 1;
}

.cell .hint {
  position: absolute;
  font-size: 0.55rem;
  color: #b0c0d4;
  bottom: 2px;
  right: 3px;
  opacity: 0.7;
}

.cell.written .hint { display: none; }

.cell.just-written .glyph {
  animation: pop-in 0.35s ease-out;
}

@keyframes pop-in {
  from { transform: scale(0.3); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.fighters {
  display: flex;
  justify-content: center;
  gap: 4px;
  min-height: 22px;
  margin-top: 6px;
  font-size: 1.1rem;
}

.rps-area, .action-area {
  background: rgba(255, 255, 255, 0.55);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 14px 12px;
  text-align: center;
}

.round-msg, .action-msg {
  font-size: 0.95rem;
  margin-bottom: 12px;
  min-height: 1.4em;
  line-height: 1.4;
}

.rps-buttons, .action-buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.rps-result {
  margin-top: 12px;
  font-size: 0.95rem;
  line-height: 1.5;
}

.rps-result .choices {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-bottom: 8px;
  font-size: 1.05rem;
  font-weight: 600;
}

.rps-result .winner-line {
  color: var(--red);
  font-weight: 700;
}

.hidden { display: none !important; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(26, 58, 107, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}

.modal-card {
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 14px;
  padding: 28px 22px;
  text-align: center;
  max-width: 300px;
  width: 100%;
  box-shadow: 4px 6px 0 var(--shadow);
  background-image:
    repeating-linear-gradient(
      transparent,
      transparent 27px,
      var(--line) 27px,
      var(--line) 28px
    );
}

.modal-card h3 {
  font-size: 1.6rem;
  margin-bottom: 10px;
  letter-spacing: 0.1em;
}

.modal-card p {
  font-size: 0.95rem;
  color: var(--ink-soft);
  margin-bottom: 22px;
  line-height: 1.45;
}

.thinking {
  opacity: 0.7;
  font-style: italic;
}

@media (min-width: 400px) {
  .fortress { width: 176px; }
  .cell { min-height: 58px; }
}
