:root {
    --color-bg: #ffffff;
    --color-text: #e5e7eb;
    --color-text-muted: #ffffff;
    --color-primary: #bf2e2e;
    --color-primary-hover: #c56c6c;
    --color-accent: #facc15;
    --color-danger: #e11d48;
    --color-danger-hover: #f43f5e;
    --color-surface-800: #1f2937;
    --color-surface-900: #111827;
    --color-success: #10b981;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
    background-color: var(--color-bg);
    color: var(--color-text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background-image: url('../images/background.jpg');
    background-position: center center;
    background-repeat: no-repeat;
    background-size: cover;
    background-attachment: fixed;
}

.font-mono {
    font-family: 'SF Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', monospace;
}

.hidden {
    display: none !important;
}

#app-container {
    min-height: 100vh;
    width: 100%;
    display: flex;
    flex-direction: column;
    padding: 1rem;
}

#stats-bar {
    width: 100%;
    max-width: 576px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: rgba(114, 41, 41, 0.5);
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    margin-top: 1rem;
    font-size: 1.125rem;
}

#stats-bar .stat span {
    font-weight: bold;
    color: white;
}

#reset-button {
    background-color: var(--color-danger);
    color: white;
    font-weight: bold;
    padding: 0.25rem 1rem;
    border-radius: 0.5rem;
    border: none;
    cursor: pointer;
    transition: transform 0.2s, background-color 0.2s;
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

#reset-button:hover {
    background-color: var(--color-danger-hover);
    transform: scale(1.05);
}

#game-container {
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 576px;
    margin: 0 auto;
    position: relative;
}

@media (min-width: 768px) {
    #game-container {
        /* 77vh * aspect ratio (5/7) */
        max-width: calc(77vh * 0.7142857);
    }

    #stats-bar {
        max-width: calc(77vh * 0.7142857);
    }
}

#game-board {
    width: 100%;
    border-radius: 0.5rem;
    overflow: hidden;
    position: relative;
    /* Aspect ratio for 4x4 grid of 5:7 cards -> (4*5) / (4*7) = 5/7 */
    aspect-ratio: 5 / 7;
}

.card-wrapper {
    padding: 2%;
    perspective: 1000px;
    position: absolute;
    transition: transform 0.5s;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    cursor: pointer;
    transform-style: preserve-3d;
    transition: transform 0.5s;
}

.card-wrapper.is-flipped .card-inner {
    transform: rotateY(180deg);
}

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 0.5rem;
    box-shadow: 0 8px 8px 0px rgb(0 0 0 / 0.2), 0 2px 2px 0 rgb(0 0 0 / 0.4);
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.card-face img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card-back {
    background-color: var(--color-primary);
}

.card-front {
    background-color: #e2e8f0;
    transform: rotateY(180deg);
}

.card-wrapper.is-matched .card-front {
    background-color: var(--color-success);
    opacity: 0.7;
}

.card-wrapper.is-matched .card-inner {
    transform: rotateY(180deg);
    cursor: default;
}


/* Overlays and Modals */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

.overlay.visible {
    opacity: 1;
    visibility: visible;
}

.overlay::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0);
    backdrop-filter: blur(2px);
}

.overlay-content {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-size: cover;
    background-position: center;
}

.start-content {
    background-image: url('../images/modal-bg-start.png');
}

#start-button {
    position: relative;
    z-index: 10;
    background-color: var(--color-primary);
    color: white;
    font-weight: bold;
    padding: 1.25rem 2.5rem;
    font-size: 1.5rem;
    border-radius: 0.5rem;
    border: none;
    cursor: pointer;
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    transition: transform 0.2s, background-color 0.2s;
    transform: translateY(6rem);
}

#start-button:hover {
    background-color: var(--color-primary-hover);
    transform: translateY(6rem) scale(1.05);
}

#game-over-modal {
    position: fixed;
    z-index: 50;
    padding: 1rem;
    background-color: rgba(255, 255, 255, 0);
}

.modal-content {
    position: relative;
    width: 100%;
    max-width: 42rem;
    padding: 5rem;
    text-align: center;
    border-radius: 0.5rem;
    background-image: url('../images/modal-bg-clear.png');
    background-size: cover;
    background-position: center;
    overflow: hidden;
}

.modal-content::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

/* スマホ専用（768px未満） */
@media (max-width: 767px) {
    .modal-content {
        padding: 0rem;
        /* パディングを少し狭く */
        max-width: 100%;
        /* 横幅をほぼ画面いっぱいに */
        border-radius: 0.25rem;
        /* 角を少し丸め */
        background-size: cover;
        /* 画像を要素いっぱいに拡大縮小 */
        background-position: center;
        /* 画像を中央に配置 */
        background-repeat: no-repeat;
        /* ← これで繰り返しを無効化！ */
        font-size: 0.9rem;
        /* 文字サイズをやや小さめに */
    }

    .stat-value {
        font-size: 2.5rem;
        /* 数値を縮小 */
    }

    #restart-button {
        font-size: 1.25rem;
        padding: 1rem 1.25rem;
        width: 90%;
    }
}

.modal-stats,
#restart-button {
    position: relative;
    z-index: 1;
}

.modal-stats {
    margin: 3rem 0;
}

.modal-stats>div:first-child {
    margin-bottom: 2rem;
}

.stat-label {
    color: var(--color-text-muted);
    font-size: 1.875rem;
}

.stat-value {
    font-weight: bold;
    color: var(--color-accent);
    font-size: 4.5rem;
    letter-spacing: 0.05em;
}

@media (max-width: 767px) {
    .stat-value {
        font-size: 2.5rem;
        /* 数値を縮小 */
    }
}


#restart-button {
    width: 80%;
    background-color: var(--color-primary);
    color: white;
    font-weight: bold;
    padding: 1.25rem 1.5rem;
    font-size: 1.875rem;
    border-radius: 0.5rem;
    border: none;
    cursor: pointer;
    transition: transform 0.2s, background-color 0.2s;
}

#restart-button:hover {
    background-color: var(--color-primary-hover);
    transform: scale(1.05);
}

.footer {
    flex-shrink: 0;
    text-align: center;
    color: #000000;
    font-size: 0.875rem;
    padding: 1rem 0;
}

#site-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  display: none; /* 初期状態では非表示 */
  justify-content: center;
  align-items: center;
  flex-direction: column;
  z-index: 9999;
  text-align: center;
  font-family: "Noto Sans JP", sans-serif;
}

#site-mask.visible {
  display: flex;
}

#site-mask h1 {
  font-size: 2rem;
  margin-bottom: 1rem;
}

#site-mask p {
  font-size: 1.2rem;
  color: #ccc;
}
