*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "LINE Seed JP", sans-serif;
  background: #f2f3f7;
  color: #222;
}

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  padding: 1.5rem 1.25rem 0.5rem;
  text-align: center;
  position: relative;
}

.header-with-exit .title {
  margin: 0;
  font-size: 1.7rem;
}

.header-exit-button {
  position: absolute;
  left: 1.25rem;
  top: 1.1rem;
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
}

.subtitle {
  margin: 0.25rem 0 0;
  font-size: 0.9rem;
  color: #555;
}

.main {
  flex: 1;
  padding: 1rem 1.25rem 2rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
}

@media (min-width: 768px) {
  .main {
    grid-template-columns: minmax(0, 1fr);
  }

  .main .help {
    grid-column: 1 / -1;
  }
}

.panel {
  background: #ffffff;
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  box-shadow: 0 8px 16px rgba(15, 23, 42, 0.08);
}

.panel-secondary {
  align-self: stretch;
}

.panel-title {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
}

.panel-text {
  margin: 0 0 1rem;
  font-size: 0.9rem;
  color: #444;
  line-height: 1.6;
}

.join-form {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.input {
  flex: 1 1 120px;
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 1.1rem;
  font-size: 0.95rem;
  border-radius: 999px;
  border: none;
  background: #e5e7eb;
  color: #111827;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, transform 0.05s ease, box-shadow 0.15s ease;
  box-shadow: 0 2px 4px rgba(15, 23, 42, 0.1);
}

.button.primary {
  background: linear-gradient(200deg, #55cb96, #329b6a);
  color: #ffffff;
}

.button-warning {
  background: linear-gradient(200deg, #e8c53c, #b69c0b);
  color: #ffffff;
}

.button-danger {
  background: linear-gradient(200deg, #e6637b, #ca3e58);
  color: #ffffff;
}

.button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(15, 23, 42, 0.15);
}

.button:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px rgba(15, 23, 42, 0.1);
}

.button:disabled {
  background: #ccc;
  color: #888;
  cursor: default;
  box-shadow: none;
  transform: none;
  pointer-events: none;
}

.button:disabled:hover {
  box-shadow: none;
  transform: none;
}

.button.link-button {
  margin-top: 1rem;
  background: linear-gradient(200deg, #e6637b, #ca3e58);
  color: #ffffff;
  padding-left: 1.5rem;
  border-top-left-radius: 999px;
  border-bottom-left-radius: 999px;
  border-top-right-radius: 200px;
  border-bottom-right-radius: 200px;
}

.help-list {
  margin: 0.25rem 0 0.75rem 1.25rem;
  padding: 0;
  font-size: 0.9rem;
  color: #444;
  line-height: 1.6;
}

.help-note {
  margin: 0;
  font-size: 0.8rem;
  color: #6b7280;
}

.footer {
  padding: 0.75rem 1.25rem 1rem;
  text-align: center;
  font-size: 0.75rem;
  color: #9ca3af;
}

.message {
  max-width: 960px;
  margin: 0 auto;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  font-size: 0.9rem;
}

.message-error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.room-code-wrapper {
  margin-top: 0.75rem;
}

.room-code-label {
  display: block;
  font-weight: 600;
  color: #1f2937;
  font-size: 0.85rem;
  margin-bottom: 0.25rem;
}

.room-code-box {
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  background: #f3f4f6;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.room-code-input {
  flex: 1 1 auto;
  border: none;
  outline: none;
  background: transparent;
  font-size: 0.95rem;
  color: #111827;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0;
}

.icon-button .icon {
  width: 18px;
  height: 18px;
  fill: #6b7280;
}

.icon-button:hover .icon {
  fill: #374151;
}

.icon-button .icon.icon-clipboard {
  fill: none;
  stroke: currentColor;
  color: #6b7280;
}

.icon-button:hover .icon.icon-clipboard {
  color: #374151;
}

.copy-status {
  font-size: 0.75rem;
  color: #6b7280;
}

.match-status {
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: #374151;
}

.match-status-label {
  font-weight: 600;
}

.phase {
  margin-top: 1.25rem;
}

.phase-playing {
  position: relative;
  padding-bottom: 400px;
}

.phase-confirming {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.ready-button {
  min-width: 180px;
  justify-content: center;
}

.phase-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: #111827;
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
}

.turn-timer {
  font-size: 0.95rem;
  color: #374151;
}

.turn-timer--danger {
  color: #b91c1c;
  font-weight: 700;
}

.phase-note {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  color: #6b7280;
  text-align: center;
}

/* 手牌入力 */
.hand-input-section {
  margin-top: 1rem;
}

.hand-eval {
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  min-height: 1.4em;
}

.hand-eval--agari {
  color: #0d823a;
  font-weight: 600;
}

.hand-eval--shanten {
  color: #b91c1c;
  font-weight: 600;
}

.hand-label {
  margin: 0.5rem 0;
  font-size: 0.9rem;
  color: #374151;
}

.hand-slots {
  display: flex;
  flex-wrap: nowrap;
  gap: 2px;
  margin-bottom: 1rem;
  min-height: 49px;
}

.hand-slot {
  width: 37px;
  min-width: 37px;
  height: 49px;
  border: 2px solid #88888855;
  border-radius: 3px;
  background: #f9fafb;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  position: relative;
}

.hand-slot img {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.hand-slot--cursor {
  border: 2px dashed #5b95f1;
  background: #eff6ff;
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.3);
}

.hand-slot-ron-wrap {
  position: relative;
  width: 37px;
  min-width: 37px;
  height: 49px;
  flex-shrink: 0;
  margin-left: 20px;
}

.hand-slot-ron-wrap .hand-slot {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
}

.hand-slot-ron-label {
  position: absolute;
  top: -0.95em;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.65rem;
  font-weight: 600;
  color: #6b7280;
  line-height: 1;
  white-space: nowrap;
}

.time-up-history {
  margin-left: 0 !important;
  width: 100px !important;
  border: none !important;
}

.tile-picker {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tile-picker-row {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
}

.tile-picker-tile {
  width: 36px;
  height: 48px;
  border: 1px solid #e5e7eb;
  border-radius: 3px;
  padding: 0;
  background: #fff;
  cursor: pointer;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s, border-color 0.15s;
}

.tile-picker-tile:hover:not(.tile-picker-tile--disabled) {
  border-color: #3b82f6;
}

.tile-picker-tile img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.tile-picker-tile--disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.tile-picker-delete {
  align-self: center;
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
  border: 1px solid #bbb;
  border-radius: 5px;
  background: #555;
  color: #eee;
  cursor: pointer;
  margin-left: 4px;
}

.tile-picker-delete:hover {
  background: #777;
  border-color: #ccc;
}

.game-scores {
  margin: 0 0 1rem 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: #111827;
}

.input-panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 360px;
  z-index: 99;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  pointer-events: none;
}

.input-panel-inner {
  position: relative;
  width: min(800px, 100% - 3rem);
  margin: 0 auto;
  padding: 0.75rem 1rem 2.25rem;
  border-radius: 16px 16px 0 0;
  background: rgba(200, 200, 200, 0.3);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.25);
  pointer-events: auto;
}

.input-panel-inner--disabled .tile-picker,
.input-panel-inner--disabled .input-main-button-row {
  opacity: 0.4;
}


.input-panel--collapsed {
  transform: translateY(calc(100% - 32px));
}

.input-panel {
  transition: transform 0.2s ease-out;
}

.hand-building-panel {
  background: #f3f4f6;
  border-radius: 12px;
  padding: 0.75rem 0.9rem 1rem;
  margin: 0.5rem 0 1rem;
  max-width: 100%;
}

.hand-build-row {
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  gap: 0.75rem;
}

.input-main-row {
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  gap: 0.75rem;
}

.hand-set-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0 0 1.25rem 0;
  flex-shrink: 0;
}

.input-main-button-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0 0 1.25rem 0;
  flex-shrink: 0;
}

.input-panel-toggle {
  position: absolute;
  left: 50%;
  top: -0.8rem;
  transform: translateX(-50%);
  width: 32px;
  height: 24px;
  border-radius: 999px;
  border: 1px solid #d1d5db;
  background: rgba(255, 255, 255, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.8rem;
  color: #4b5563;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.2);
}

.input-panel-toggle:hover {
  background: #f9fafb;
}

.hand-set-note {
  font-size: 0.85rem;
  color: #6b7280;
  text-align: center;
}

.button-set-hand {
  flex-shrink: 0;
}

.hand-slots--readonly .hand-slot {
  cursor: default;
}

.answer-turn-block .hand-label {
  margin-top: 0.75rem;
}

.answer-turn-block .hand-label:first-of-type {
  margin-top: 0;
}

.guess-input-panel {
  background: #f3f4f6;
  border-radius: 12px;
  padding: 0.75rem 1rem;
  margin: 0.5rem 0 1rem;
  max-width: 100%;
}

.guess-row {
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  gap: 0.75rem;
}

.input-panel-footer {
  margin: 0 calc(2.8rem + 6px) 0;
}

/* 入力パネル内の牌入力キーを左右中央揃え */
.input-panel-footer .tile-picker {
  align-items: center;
}

.input-panel-footer .tile-picker-row {
  justify-content: center;
}

.answer-turn-note {
  margin: 0.3rem 0 0.5rem;
  font-size: 0.9rem;
  color: #374151;
  text-align: center;
}

.guess-submit-row {
  margin: 0 0 1.25rem 0;
}

.guess-slots .hand-slot--hit {
  border-color: rgb(21, 186, 82);
  box-shadow: 0 0 0 1px rgba(22, 176, 78, 0.3);
}

.guess-slots .hand-slot--blow {
  border-color: rgb(220, 192, 13);
  box-shadow: 0 0 0 1px rgba(220, 192, 13, 0.3);
}

.guess-slots--opponent {
  opacity: 0.5;
  pointer-events: none;
}

.answer-history-section {
  margin-top: 1.25rem;
}

.answer-history-section .hand-label {
  margin-bottom: 0.35rem;
}

.answer-history {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 220px;
  overflow-y: auto;
}

.answer-history-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  align-items: center;
}

.answer-history-row-label {
  flex: 0 0 auto;
  font-size: 0.8rem;
  color: #6b7280;
  width: 3.5em;
}

.answer-history-row-tiles {
  display: flex;
  flex-wrap: nowrap;
  gap: 2px;
  pointer-events: none;
}

.answer-history-row .hand-slot--hit {
  border-color: rgb(21, 186, 82);
}

.answer-history-row .hand-slot--blow {
  border-color: rgb(220, 192, 13);
}

.answer-tabs {
  margin: 1.5rem auto 0;
  display: flex;
  gap: 0.5rem;
  border-bottom: 1px solid #e5e7eb;
  max-width: 800px;
}

.answer-tab-button {
  padding: 0.4rem 0.9rem;
  font-size: 0.9rem;
  border: none;
  background: transparent;
  cursor: pointer;
  color: #6b7280;
  border-bottom: 2px solid transparent;
}

.answer-tab-button--active {
  color: #111827;
  font-weight: 600;
  border-bottom-color: #2563eb;
}

.answer-tabs-body {
  margin-top: 0.75rem;
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
}

.answer-tab-panel {
  display: none;
}

.answer-tab-panel--active {
  display: block;
}

.answer-tab-hand {
  margin-bottom: 0.75rem;
}

.answer-tab-hand .hand-slots {
  margin-left: calc(2.8rem + 6px);
}

.my-hand-bottom {
  margin-top: 1.25rem;
  padding-top: 0.75rem;
  border-top: 1px solid #e5e7eb;
}

.my-hand-bottom .hand-label--compact {
  font-size: 0.85rem;
  color: #6b7280;
  margin-bottom: 0.25rem;
}

/* 回答エリア3種の1牌目横位置を揃える（巡目ラベル幅 3.5em=2.8rem @ 0.8rem + gap 6px） */
.hand-build-row .hand-slots {
  margin-left: calc(2.8rem + 6px);
}

.guess-slots {
  margin-left: calc(2.8rem + 6px);
}

.my-hand-bottom .hand-slots {
  margin-left: calc(2.8rem + 6px);
}

/* ロン牌のスペースを履歴・自分の手牌にも統一的に付与 */
.answer-history-row-tiles .hand-slot:last-child,
.my-hand-bottom .hand-slots .hand-slot:last-child,
.answer-tab-hand .hand-slots .hand-slot:last-child {
  margin-left: 20px;
}

.result-modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
}

.result-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
}

.result-modal-dialog {
  position: relative;
  z-index: 41;
  background: #ffffff;
  border-radius: 12px;
  padding: 1.5rem 1.75rem;
  max-width: 480px;
  width: calc(100% - 2rem);
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.35);
  text-align: center;
}

.result-modal-title {
  margin: 0 0 0.75rem;
  font-size: 1.2rem;
  font-weight: 700;
  color: #111827;
}

.result-modal-hand {
  margin: 0 0 0.75rem;
  display: flex;
  justify-content: center;
  gap: 1px;
}

.result-modal-opponent-label {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  color: #6b7280;
}

.result-modal-hand .hand-slot {
  width: 28px;
  min-width: 28px;
  height: 37px;
}

.result-modal-note {
  margin: 0 0 1rem;
  font-size: 0.9rem;
  color: #4b5563;
}


.hand-slot--blow::before {
  content: "";
  position: absolute;
  inset: 0;
  background:linear-gradient(-135deg, transparent 0 87%, #eec00d 87% 100%) top right;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  pointer-events: none;
  z-index: 2;
}

/* Hit を Blow より視覚的に強調するためのコーナー装飾 */
.hand-slot--hit::before {
  content: "";
  position: absolute;
  inset: 0;
  background:linear-gradient(-135deg, #22c55e 0 13%, transparent 13% 87%, #22c55e 87% 100%) top right;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  pointer-events: none;
  z-index: 2;
}

.pop-in {
  animation: pop-in 0.15s ease-out;
}

@keyframes pop-in {
  0% {
    transform: scale(0.5);
  }
  60% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
  }
}